bes-service is a small bash bes library to easily create systemd service
Go to file
2019-03-05 00:10:50 +01:00
src version 1.1 2019-03-05 00:10:50 +01:00
bes.ini version 1.1 2019-03-05 00:10:50 +01:00
README.md version 1.1 2019-03-05 00:10:50 +01:00

bes-service

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

Usage

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

[require]
bes.service = 1.1

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_CHANNEL="mychannel"
 BES_SERVICE_DELAY=10
  BES_SERVICE_BOOT=0

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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