version 1.1

This commit is contained in:
a-Sansara 2019-03-04 22:40:32 +01:00
parent 18b03c00f2
commit ae0893a718
4 changed files with 15 additions and 19 deletions

View File

@ -5,11 +5,11 @@ bes-service is a small bash bes library to easily create systemd service.
### Usage ### Usage
add bes-service as dependency in bes.ini file of your project. add bes-service as dependency in your bes.ini file.
``` ```
[require] [require]
bes.service = 1.0 bes.service = 1.1
``` ```
create your service following 'src/main.sh.tpl' template. create your service following 'src/main.sh.tpl' template.
@ -25,9 +25,9 @@ edit for example 'src/main.sh' in your bes project ('myservice' in this example)
# #
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_SERVICE_NAME="myservice" BES_SERVICE_NAME="myservice"
BES_SERVICE_LOGGER="myservice.type1" BES_SERVICE_CHANNEL="mychannel"
BES_SERVICE_DELAY=10 BES_SERVICE_DELAY=10
BES_SERVICE_BOOT=1 BES_SERVICE_BOOT=0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# optional - service is started, do before running # optional - service is started, do before running
@ -87,5 +87,3 @@ inspect service log :
``` ```
tail -f /var/log/myservice.log tail -f /var/log/myservice.log
``` ```

View File

@ -1,7 +1,7 @@
[project] [project]
vendor = bes vendor = bes
name = service name = service
version = 1.0 version = 1.1
license = "GNU GPL v3" license = "GNU GPL v3"
author = a-Sansara author = a-Sansara
type = library type = library

View File

@ -7,7 +7,7 @@
# #
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BES_SERVICE_NAME="myservice" BES_SERVICE_NAME="myservice"
BES_SERVICE_LOGGER="myservice.type1" BES_SERVICE_CHANNEL="myservice.type1"
BES_SERVICE_DELAY=10 BES_SERVICE_DELAY=10
BES_SERVICE_BOOT=1 BES_SERVICE_BOOT=1

View File

@ -10,9 +10,11 @@
function bes.service.boot () function bes.service.boot ()
{ {
BES_SERVICE_NAME="yourservice" BES_SERVICE_NAME="yourservice"
BES_SERVICE_LOGGER="channel1" BES_SERVICE_CHANNEL="channel1"
BES_SERVICE_DELAY=0 BES_SERVICE_DELAY=0
BES_SERVICE_BOOT=0 BES_SERVICE_BOOT=0
BES_SERVICE_LOG="/var/log/$BES_SERVICE_NAME.log"
BES_SERVICE_RUN_DIR="/run/$BES_SERVICE_NAME"
} }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function service.time() function service.time()
@ -28,7 +30,7 @@ function service.log()
if [ "$display" = "1" ]; then if [ "$display" = "1" ]; then
echo "[$dt] $msg"; echo "[$dt] $msg";
fi fi
echo "[$dt] $BES_SERVICE_LOGGER $msg" >> "$BES_SERVICE_LOG" echo "[$dt] $BES_SERVICE_CHANNEL $msg" >> "$BES_SERVICE_LOG"
} }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function service.init() function service.init()
@ -95,8 +97,8 @@ function service.run()
service.on.run service.on.run
elif [ "$BES_SERVICE_DELAY" -gt 0 ]; then elif [ "$BES_SERVICE_DELAY" -gt 0 ]; then
while true; do while true; do
sleep $BES_SERVICE_DELAY
service.on.run service.on.run
sleep $BES_SERVICE_DELAY
done done
fi fi
fi fi
@ -138,8 +140,6 @@ WantedBy=multi-user.target
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function service.launch() function service.launch()
{ {
export BES_SERVICE_LOG="/var/log/$BES_SERVICE_NAME.log"
export BES_SERVICE_RUN_DIR="/run/$BES_SERVICE_NAME"
case "$1" in case "$1" in
install) install)
service.install "$2" service.install "$2"
@ -159,8 +159,6 @@ function service.launch()
esac esac
} }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare -f bes.reg > /dev/null if bes.exists bes.reg; then
if [ $? -eq 0 ]; then
bes.reg bes.service bes.reg bes.service
fi fi