/rc4.d/S50saned

http://github.com/brinkman83/bashrc · Shell · 95 lines · 68 code · 10 blank · 17 comment · 9 complexity · af2d2e5f4762c4d6ed9b8874c830d148 MD5 · raw file

  1. #! /bin/sh
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides: saned
  5. # Required-Start: $syslog $local_fs
  6. # Required-Stop: $syslog $local_fs
  7. # Should-Start: dbus avahi
  8. # Should-Stop: dbus avahi
  9. # Default-Start: 2 3 4 5
  10. # Default-Stop: 1
  11. # Short-Description: SANE network scanner server
  12. # Description: saned makes local scanners available over the
  13. # network.
  14. ### END INIT INFO
  15. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  16. DAEMON=/usr/sbin/saned
  17. NAME=saned
  18. DESC="SANE network scanner server"
  19. test -x $DAEMON || exit 0
  20. RUN=no
  21. RUN_AS_USER=saned
  22. # Include saned defaults if available
  23. if [ -f /etc/default/saned ] ; then
  24. . /etc/default/saned
  25. fi
  26. if [ "x$RUN" != "xyes" ] ; then
  27. exit 0
  28. fi
  29. DAEMON_OPTS="-a $RUN_AS_USER"
  30. set -e
  31. case "$1" in
  32. start)
  33. echo -n "Starting $DESC: "
  34. start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
  35. --exec $DAEMON -- $DAEMON_OPTS
  36. echo "$NAME."
  37. ;;
  38. stop)
  39. echo -n "Stopping $DESC: "
  40. start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/$NAME.pid \
  41. --exec $DAEMON
  42. echo "$NAME."
  43. ;;
  44. force-reload)
  45. # check whether $DAEMON is running. If so, restart
  46. start-stop-daemon --stop --test --quiet --pidfile \
  47. /var/run/$NAME.pid --exec $DAEMON \
  48. && $0 restart \
  49. || exit 0
  50. ;;
  51. restart)
  52. echo -n "Restarting $DESC: "
  53. start-stop-daemon --stop --oknodo --quiet --pidfile \
  54. /var/run/$NAME.pid --exec $DAEMON
  55. sleep 1
  56. start-stop-daemon --start --quiet --pidfile \
  57. /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
  58. echo "$NAME."
  59. ;;
  60. status)
  61. if [ -s /var/run/$NAME.pid ]; then
  62. RUNNING=$(cat /var/run/$NAME.pid)
  63. if [ -d /proc/$RUNNING ]; then
  64. if [ $(readlink /proc/$RUNNING/exe) = $DAEMON ]; then
  65. echo "$NAME is running."
  66. exit 0
  67. fi
  68. fi
  69. # No such PID, or executables don't match
  70. echo "$NAME is not running, but pidfile existed."
  71. rm /var/run/$NAME.pid
  72. exit 1
  73. else
  74. rm -f /var/run/$NAME.pid
  75. echo "$NAME not running."
  76. exit 1
  77. fi
  78. ;;
  79. *)
  80. N=/etc/init.d/$NAME
  81. echo "Usage: $N {start|stop|restart|force-reload}" >&2
  82. exit 1
  83. ;;
  84. esac
  85. exit 0