mirror of
https://github.com/AuxXxilium/arv-v-dsm.git
synced 2024-11-24 07:20:57 +07:00
50 lines
843 B
Bash
50 lines
843 B
Bash
#!/bin/bash
|
|
|
|
PIDFILE="/var/run/agent.pid"
|
|
LOGFILE="/var/log/agent.log"
|
|
SCRIPT="/usr/local/bin/agent.sh"
|
|
|
|
status() {
|
|
if [ -f "$PIDFILE" ]; then
|
|
echo 'Service running' >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
start() {
|
|
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
|
|
echo 'Service already running' >&2
|
|
return 1
|
|
fi
|
|
printf 'Starting agent service...' >&2
|
|
"$SCRIPT" &> "$LOGFILE" & echo $! > "$PIDFILE"
|
|
}
|
|
|
|
stop() {
|
|
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
|
|
echo 'Service not running' >&2
|
|
return 1
|
|
fi
|
|
echo 'Stopping agent service' >&2
|
|
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
|
|
echo 'Service stopped' >&2
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
status)
|
|
status
|
|
;;
|
|
restart)
|
|
stop
|
|
start
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart}"
|
|
esac
|