/rc5.d/S50cups

http://github.com/brinkman83/bashrc · Shell · 116 lines · 88 code · 14 blank · 14 comment · 24 complexity · f4412c6b8ae3c5ac5491e418d2a23a2b MD5 · raw file

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: cups
  4. # Required-Start: $syslog $remote_fs
  5. # Required-Stop: $syslog $remote_fs
  6. # Should-Start: $network avahi
  7. # Should-Stop: $network
  8. # X-Start-Before: samba
  9. # X-Stop-After: samba
  10. # Default-Start: 2 3 4 5
  11. # Default-Stop: 1
  12. # Short-Description: CUPS Printing spooler and server
  13. ### END INIT INFO
  14. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  15. DAEMON=/usr/sbin/cupsd
  16. NAME=cupsd
  17. PIDFILE=/var/run/cups/$NAME.pid
  18. DESC="Common Unix Printing System"
  19. unset TMPDIR
  20. test -x $DAEMON || exit 0
  21. mkdir -p /var/run/cups/certs
  22. if [ -r /etc/default/cups ]; then
  23. . /etc/default/cups
  24. fi
  25. . /lib/lsb/init-functions
  26. # Get the timezone set.
  27. if [ -z "$TZ" -a -e /etc/timezone ]; then
  28. TZ=`cat /etc/timezone`
  29. export TZ
  30. fi
  31. restart_xprint() {
  32. if [ -n "$success" ] && [ -x /etc/init.d/xprint ]; then
  33. invoke-rc.d xprint force-reload || true
  34. fi
  35. }
  36. coldplug_usb_printers() {
  37. if type udevadm > /dev/null 2>&1 && [ -x /lib/udev/udev-configure-printer ]; then
  38. for printer in `udevadm trigger --verbose --dry-run --subsystem-match=usb \
  39. --attr-match=bInterfaceClass=07 --attr-match=bInterfaceSubClass=01 2>/dev/null || true; \
  40. udevadm trigger --verbose --dry-run --subsystem-match=usb \
  41. --sysname-match='lp[0-9]*' 2>/dev/null || true`; do
  42. /lib/udev/udev-configure-printer add "${printer#/sys}"
  43. done
  44. fi
  45. }
  46. case "$1" in
  47. start)
  48. log_begin_msg "Starting $DESC: $NAME"
  49. chown root:lpadmin /usr/share/ppd/custom 2>/dev/null || true
  50. chmod 3775 /usr/share/ppd/custom 2>/dev/null || true
  51. mkdir -p `dirname "$PIDFILE"`
  52. if [ "$LOAD_LP_MODULE" = "yes" -a -f /usr/lib/cups/backend/parallel \
  53. -a -f /proc/devices -a -f /proc/modules -a -x /sbin/modprobe ]; then
  54. modprobe -q -b lp || true
  55. modprobe -q -b ppdev || true
  56. fi
  57. start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" --exec $DAEMON && success=1
  58. coldplug_usb_printers
  59. log_end_msg $?
  60. restart_xprint
  61. ;;
  62. stop)
  63. log_begin_msg "Stopping $DESC: $NAME"
  64. start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME && success=1
  65. log_end_msg $?
  66. restart_xprint
  67. ;;
  68. reload|force-reload)
  69. log_begin_msg "Reloading $DESC: $NAME"
  70. start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --signal 1 && success=1
  71. log_end_msg $?
  72. restart_xprint
  73. ;;
  74. restart)
  75. log_begin_msg "Restarting $DESC: $NAME"
  76. if start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME; then
  77. start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec $DAEMON && success=1
  78. fi
  79. log_end_msg $?
  80. restart_xprint
  81. ;;
  82. status)
  83. echo -n "Status of $DESC: "
  84. if [ ! -r "$PIDFILE" ]; then
  85. echo "$NAME is not running."
  86. exit 3
  87. fi
  88. if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
  89. echo "$NAME is running."
  90. exit 0
  91. else
  92. echo "$NAME is not running but $PIDFILE exists."
  93. exit 1
  94. fi
  95. ;;
  96. *)
  97. N=/etc/init.d/${0##*/}
  98. echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
  99. exit 1
  100. ;;
  101. esac
  102. exit 0