You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
958 B

#!/bin/sh
DAEMON=/usr/bin/tera-sessiond
PIDFILE=/run/tera-sessiond.pid
ENVFILE=/etc/tera/tera-sessiond.env
RUN_AS=tera:tera
load_environment() {
if [ -r "$ENVFILE" ]; then
set -a
. "$ENVFILE"
set +a
fi
}
is_running() {
[ -r "$PIDFILE" ] || return 1
pid="$(cat "$PIDFILE" 2>/dev/null)"
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
}
start_service() {
if is_running; then
echo "tera-sessiond is already running"
return 0
fi
rm -f "$PIDFILE"
[ -x "$DAEMON" ] || { echo "missing $DAEMON" >&2; return 1; }
load_environment
start-stop-daemon -S -q -b -m -p "$PIDFILE" -c "$RUN_AS" -x "$DAEMON"
}
stop_service() {
if ! is_running; then
rm -f "$PIDFILE"
return 0
fi
start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON"
rm -f "$PIDFILE"
}
case "$1" in
start) start_service ;;
stop) stop_service ;;
restart) stop_service && start_service ;;
status) is_running ;;
*) echo "Usage: $0 {start|stop|restart|status}" >&2; exit 1 ;;
esac