/init.d/danted

http://github.com/brinkman83/bashrc · Shell · 92 lines · 60 code · 6 blank · 26 comment · 4 complexity · 8577392e4bfeefd29a96e8ff7e7ffb43 MD5 · raw file

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: danted
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: SOCKS (v4 and v5) proxy daemon (danted)
  9. ### END INIT INFO
  10. #
  11. # dante SOCKS server init.d file. Based on /etc/init.d/skeleton:
  12. # Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl
  13. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  14. DAEMON=/usr/sbin/danted
  15. NAME=danted
  16. DESC="Dante SOCKS daemon"
  17. PIDFILE=/var/run/$NAME.pid
  18. CONFFILE=/etc/$NAME.conf
  19. test -f $DAEMON || exit 0
  20. set -e
  21. # This function makes sure that the Dante server can write to the pid-file.
  22. touch_pidfile ()
  23. {
  24. if [ -r $CONFFILE ]; then
  25. uid="`sed -n -e 's/[[:space:]]//g' -e 's/#.*//' -e '/^user\.privileged/{s/[^:]*://p;q;}' $CONFFILE`"
  26. if [ -n "$uid" ]; then
  27. touch $PIDFILE
  28. chown $uid $PIDFILE
  29. fi
  30. fi
  31. }
  32. case "$1" in
  33. start)
  34. if ! egrep -cve '^ *(#|$)' \
  35. -e '^(logoutput|user\.((not)?privileged|libwrap)):' \
  36. $CONFFILE > /dev/null
  37. then
  38. echo "Not starting $DESC: not configured."
  39. exit 0
  40. fi
  41. echo -n "Starting $DESC: "
  42. touch_pidfile
  43. start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE \
  44. --exec $DAEMON -- -D
  45. echo "$NAME."
  46. ;;
  47. stop)
  48. echo -n "Stopping $DESC: "
  49. start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
  50. --exec $DAEMON
  51. echo "$NAME."
  52. ;;
  53. reload|force-reload)
  54. #
  55. # If the daemon can reload its config files on the fly
  56. # for example by sending it SIGHUP, do it here.
  57. #
  58. # If the daemon responds to changes in its config file
  59. # directly anyway, make this a do-nothing entry.
  60. #
  61. echo "Reloading $DESC configuration files."
  62. start-stop-daemon --stop --signal 1 --quiet --pidfile \
  63. $PIDFILE --exec $DAEMON -- -D
  64. ;;
  65. restart)
  66. #
  67. # If the "reload" option is implemented, move the "force-reload"
  68. # option to the "reload" entry above. If not, "force-reload" is
  69. # just the same as "restart".
  70. #
  71. echo -n "Restarting $DESC: "
  72. start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
  73. sleep 1
  74. touch_pidfile
  75. start-stop-daemon --start --quiet --pidfile $PIDFILE \
  76. --exec $DAEMON -- -D
  77. echo "$NAME."
  78. ;;
  79. *)
  80. N=/etc/init.d/$NAME
  81. # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  82. echo "Usage: $N {start|stop|restart|force-reload}" >&2
  83. exit 1
  84. ;;
  85. esac
  86. exit 0