bes-service/README.md

90 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2019-03-02 01:23:24 +00:00
bes-service
========
bes-service is a small bash bes library to easily create systemd service.
### Usage
2019-03-04 21:40:32 +00:00
add bes-service as dependency in your bes.ini file.
2019-03-02 01:23:24 +00:00
```
[require]
2019-03-04 21:40:32 +00:00
bes.service = 1.1
2019-03-02 01:23:24 +00:00
```
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"
2019-03-04 21:40:32 +00:00
BES_SERVICE_CHANNEL="mychannel"
2019-03-02 01:23:24 +00:00
BES_SERVICE_DELAY=10
2019-03-04 21:40:32 +00:00
BES_SERVICE_BOOT=0
2019-03-02 01:23:24 +00:00
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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
```