bes-service is a small bash bes library to easily create systemd service
Go to file
2019-03-02 03:18:26 +01:00
src initial commit 2019-03-02 03:18:26 +01:00
bes.ini initial commit 2019-03-02 03:18:26 +01:00
README.md initial commit 2019-03-02 03:18:26 +01:00

bes-service

bes-service is a small bash bes library to easily create systemd service.

Usage

add bes-service as dependency in bes.ini file of your project.

[require]
bes.service = 1.0

create your service following 'src/main.sh.tpl' template. edit for example 'src/main.sh' in your bes project ('myservice' in this example) :

#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# @author   you - url repo
# @license  licence
# @date     2017-07-07 02:21:51 CET
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  BES_SERVICE_NAME="myservice"
BES_SERVICE_LOGGER="myservice.type1"
 BES_SERVICE_DELAY=10
  BES_SERVICE_BOOT=1

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# optional - service is started, do before running
function service.on.init()
{
    service.log " >< service.on.init"
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# optional - service is stopped, do before exiting
function service.clean()
{
    service.log " >< service.clean"
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# your main service function
# oneshot if $BES_SERVICE_DELAY equal 0
# or repeat each $BES_SERVICE_DELAY seconds otherwise
function service.on.run()
{
    # do stuff
    service.log " >< do important things, every $BES_SERVICE_DELAY seconds"
}

service.launch $*

install bes dependencies :

bes-build update

build your project :

bes-build

then you call install your service with :

./dist/myservice install

and start/stop your service like others in systemd

service myservice start # stop | restart
# or
systemctl start myservice

inspect service log :

tail -f /var/log/myservice.log