Debian Codegraph @

examples/service_scripts/nebula.init.d.sh

raw
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: nebula
4 # Required-Start: $local_fs $network
5 # Required-Stop: $local_fs $network
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Description: nebula mesh vpn client
9 ### END INIT INFO
10
11 SCRIPT="/usr/local/bin/nebula -config /etc/nebula/config.yml"
12 RUNAS=root
13
14 PIDFILE=/var/run/nebula.pid
15 LOGFILE=/var/log/nebula.log
16
17 start() {
18 if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
19 echo 'Service already running' >&2
20 return 1
21 fi
22 echo 'Starting nebula service…' >&2
23 local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
24 su -c "$CMD" $RUNAS > "$PIDFILE"
25 echo 'Service started' >&2
26 }
27
28 stop() {
29 if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
30 echo 'Service not running' >&2
31 return 1
32 fi
33 echo 'Stopping nebula service…' >&2
34 kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
35 echo 'Service stopped' >&2
36 }
37
38 case "$1" in
39 start)
40 start
41 ;;
42 stop)
43 stop
44 ;;
45 restart)
46 stop
47 start
48 ;;
49 *)
50 echo "Usage: $0 {start|stop|restart}"
51 esac