Compare commits

..

No commits in common. "master" and "1.0" have entirely different histories.
master ... 1.0

4 changed files with 19 additions and 15 deletions

View File

@ -5,11 +5,11 @@ bes-service is a small bash bes library to easily create systemd service.
### Usage
add bes-service as dependency in your bes.ini file.
add bes-service as dependency in bes.ini file of your project.
```
[require]
bes.service = 1.1
bes.service = 1.0
```
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_CHANNEL="mychannel"
BES_SERVICE_LOGGER="myservice.type1"
BES_SERVICE_DELAY=10
BES_SERVICE_BOOT=0
BES_SERVICE_BOOT=1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# optional - service is started, do before running
@ -87,3 +87,5 @@ inspect service log :
```
tail -f /var/log/myservice.log
```

View File

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

View File

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

View File

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