Service definition

Service definition
This commit is contained in:
Kroese 2023-04-17 23:02:10 +02:00 committed by GitHub
commit 2435d90d27
4 changed files with 12 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -u
VERSION="4"
VERSION="5"
HEADER="VirtualDSM Agent"
# Functions
@ -123,6 +123,7 @@ delay=5000
elapsed=$((($(date +%s%N) - ts)/1000000))
if (( delay > elapsed )); then
echo "$HEADER: Ready..."
difference=$((delay-elapsed))
float=$(echo | awk -v diff="${difference}" '{print diff * 0.001}')
sleep "$float"

View File

@ -5,29 +5,31 @@ SCRIPT="/usr/local/bin/agent.sh"
status() {
if [ -f "$PIDFILE" ]; then
echo 'Service running' >&2
echo 'Service running'
return 1
fi
}
start() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
echo 'Service already running' >&2
echo 'Service already running'
return 1
fi
printf 'Starting agent service...' >&2
echo 'Starting agent service...'
chmod 666 /dev/ttyS0
"$SCRIPT" &> /dev/ttyS0 & echo $! > "$PIDFILE"
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
echo 'Service not running' >&2
echo 'Service not running'
return 1
fi
echo 'Stopping agent service' >&2
echo 'Stopping agent service...'
chmod 666 /dev/ttyS0
echo 'Stopping agent service...' > /dev/ttyS0
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
echo 'Service stopped' >&2
echo 'Service stopped'
}
case "$1" in

View File

@ -84,7 +84,7 @@ AGENT_VERSION=1
AGENT="${STORAGE}/${BASE}.agent"
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}")
if ((AGENT_VERSION < 4)); then
if ((AGENT_VERSION < 5)); then
echo "INFO: The installed VirtualDSM Agent is an outdated version, please upgrade it."
fi

View File

@ -163,7 +163,7 @@ cp /agent/service.sh $LOC/agent.sh
chmod +x $LOC/agent.sh
# Store agent version
echo "4" > "$STORAGE"/"$BASE".agent
echo "5" > "$STORAGE"/"$BASE".agent
echo "Install: Installing system partition..."