mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-19 13:17:56 +00:00
131 lines
2.9 KiB
Bash
Executable File
131 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: serval-dna
|
|
# Required-Start: $local_fs
|
|
# Required-Stop: $local_fs
|
|
# Should-Start:
|
|
# Should-Stop:
|
|
# X-Start-Before:
|
|
# X-Stop-After:
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: Serval DNA daemon
|
|
# Description: Daemon for providing Serval Mesh network services
|
|
### END INIT INFO
|
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
SCRIPTNAME=serval-dna
|
|
DESC="Serval DNA daemon"
|
|
NAME=servald
|
|
USER=serval
|
|
|
|
DEFAULTFILE=/etc/default/$SCRIPTNAME
|
|
DEFAULTFILE="${0%/*}/../default/$SCRIPTNAME"
|
|
DAEMON=/usr/local/sbin/$NAME
|
|
INSTANCEDIR=/var/local/serval/instance
|
|
SCRIPTPATH=/etc/init.d/$SCRIPTNAME
|
|
|
|
. /lib/lsb/init-functions
|
|
test -f "$DEFAULTFILE" && . "$DEFAULTFILE"
|
|
|
|
test -x "$DAEMON" || exit 0
|
|
|
|
if [ -z "$CONFFILE" ]; then
|
|
CONFFILE="$INSTANCEDIR/serval.conf"
|
|
fi
|
|
if [ -z "$PIDFILE" ]; then
|
|
PIDFILE="$INSTANCEDIR/servald.pid"
|
|
fi
|
|
|
|
if [ ! "$START_DAEMON" = "yes" -a "$1" = "start" ]; then
|
|
log_warning_msg "Not starting $DESC, disabled via $DEFAULTFILE"
|
|
exit 0
|
|
fi
|
|
|
|
if [ ! -e "$CONFFILE" ]; then
|
|
log_failure_msg "Cannot start $DESC, $CONFFILE not found"
|
|
exit 6
|
|
fi
|
|
|
|
if ! id $USER >/dev/null 2>&1; then
|
|
log_failure_msg "Cannot start $DESC, user '$USER' does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
SERVALINSTANCE_PATH="$INSTANCEDIR"
|
|
export SERVALINSTANCE_PATH
|
|
|
|
daemon_start() {
|
|
start-stop-daemon --chuid $USER --exec "$DAEMON" --user $USER --name $NAME --pidfile "$PIDFILE" --start -- start >/dev/null
|
|
}
|
|
|
|
daemon_stop() {
|
|
"$DAEMON" stop >/dev/null
|
|
#start-stop-daemon --chuid $USER --exec "$DAEMON" --user $USER --name $NAME --pidfile "$PIDFILE" --signal TERM --retry 2 --stop -- stop
|
|
}
|
|
|
|
daemon_status() {
|
|
"$DAEMON" status | grep -q '^status:running$'
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
log_daemon_msg "Starting $DESC" "$NAME"
|
|
if daemon_status; then
|
|
log_progress_msg "(already running)"
|
|
log_end_msg 0
|
|
elif daemon_start; then
|
|
log_end_msg 0
|
|
else
|
|
log_end_msg 1
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
status)
|
|
if daemon_status; then
|
|
log_success_msg "$NAME is running"
|
|
else
|
|
log_failure_msg "$NAME is not running"
|
|
fi
|
|
;;
|
|
|
|
stop)
|
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
|
if daemon_stop; then
|
|
log_end_msg 0
|
|
else
|
|
log_progress_msg "(not running)"
|
|
log_end_msg 1
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
force-reload|restart)
|
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
|
if ! daemon_stop; then
|
|
log_end_msg 1
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
if daemon_start; then
|
|
log_end_msg 0
|
|
else
|
|
log_end_msg 1
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
*)
|
|
log_warning_msg "Usage: $SCRIPTPATH {start|stop|restart|force-reload}"
|
|
log_warning_msg " start - starts system-wide $DESC"
|
|
log_warning_msg " stop - stops system-wide $DESC"
|
|
log_warning_msg " restart, force-reload - starts a new system-wide $DESC"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
|
|
# vim:sw=4:
|