2018-02-12 04:13:26 +03:00
|
|
|
#!/bin/sh
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: <NAME>
|
|
|
|
# Required-Start: $local_fs $network $named $time $syslog
|
|
|
|
# Required-Stop: $local_fs $network $named $time $syslog
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Description: <DESCRIPTION>
|
|
|
|
### END INIT INFO
|
|
|
|
|
2019-03-10 01:28:08 +03:00
|
|
|
SCRIPT=/usr/local/mesh/meshagent
|
2018-02-12 04:13:26 +03:00
|
|
|
RUNAS=root
|
|
|
|
|
|
|
|
PIDFILE=/var/run/meshagent.pid
|
|
|
|
LOGFILE=/var/log/meshagent.log
|
|
|
|
|
|
|
|
start() {
|
2019-03-02 04:13:11 +03:00
|
|
|
if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
|
2018-02-12 04:13:26 +03:00
|
|
|
echo 'Service already running' >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo 'Starting service…' >&2
|
|
|
|
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
|
2019-03-29 02:53:44 +03:00
|
|
|
cd /usr/local/mesh
|
2018-02-12 04:13:26 +03:00
|
|
|
su -c "$CMD" $RUNAS > "$PIDFILE"
|
|
|
|
echo 'Service started' >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2019-03-02 04:13:11 +03:00
|
|
|
if [ ! -f "$PIDFILE" ]; then
|
2018-02-12 04:13:26 +03:00
|
|
|
echo 'Service not running' >&2
|
|
|
|
return 1
|
2019-03-02 04:13:11 +03:00
|
|
|
else
|
2019-03-02 05:07:38 +03:00
|
|
|
pid=$( cat "$PIDFILE" )
|
|
|
|
if kill -0 $pid 2>/dev/null; then
|
2019-03-02 04:13:11 +03:00
|
|
|
echo 'Stopping service…' >&2
|
|
|
|
kill -16 $pid
|
|
|
|
echo 'Service stopped' >&2
|
2019-03-02 05:07:38 +03:00
|
|
|
else
|
|
|
|
echo 'Service not running'
|
|
|
|
fi
|
|
|
|
rm -f $"PIDFILE"
|
2018-02-12 04:13:26 +03:00
|
|
|
fi
|
|
|
|
}
|
2019-03-02 04:13:11 +03:00
|
|
|
restart(){
|
2019-03-02 05:07:38 +03:00
|
|
|
stop
|
|
|
|
start
|
2018-02-12 04:13:26 +03:00
|
|
|
}
|
2019-03-02 04:13:11 +03:00
|
|
|
status(){
|
2019-03-02 05:07:38 +03:00
|
|
|
if [ -f "$PIDFILE" ]
|
|
|
|
then
|
|
|
|
pid=$( cat "$PIDFILE" )
|
|
|
|
if kill -0 $pid 2>/dev/null; then
|
|
|
|
echo "meshagent start/running, process $pid"
|
|
|
|
else
|
|
|
|
echo 'meshagent stop/waiting'
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 'meshagent stop/waiting'
|
|
|
|
fi
|
2018-02-12 04:13:26 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-02 04:13:11 +03:00
|
|
|
|
2018-02-12 04:13:26 +03:00
|
|
|
case "$1" in
|
2019-03-02 05:07:38 +03:00
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: service meshagent {start|stop|restart|status}"
|
|
|
|
;;
|
2018-02-12 04:13:26 +03:00
|
|
|
esac
|
2019-03-02 04:13:11 +03:00
|
|
|
exit 0
|