nebula.init.d.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. SCRIPT="/usr/local/bin/nebula -config /etc/nebula/config.yml"
  11. RUNAS=root
  12. PIDFILE=/var/run/nebula.pid
  13. LOGFILE=/var/log/nebula.log
  14. start() {
  15. if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
  16. echo 'Service already running' >&2
  17. return 1
  18. fi
  19. echo 'Starting nebula service…' >&2
  20. local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
  21. su -c "$CMD" $RUNAS > "$PIDFILE"
  22. echo 'Service started' >&2
  23. }
  24. stop() {
  25. if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
  26. echo 'Service not running' >&2
  27. return 1
  28. fi
  29. echo 'Stopping nebula service…' >&2
  30. kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
  31. echo 'Service stopped' >&2
  32. }
  33. case "$1" in
  34. start)
  35. start
  36. ;;
  37. stop)
  38. stop
  39. ;;
  40. restart)
  41. stop
  42. start
  43. ;;
  44. *)
  45. echo "Usage: $0 {start|stop|restart}"
  46. esac