/init.d/apt-cacher-ng

http://github.com/brinkman83/bashrc · Shell · 87 lines · 60 code · 14 blank · 13 comment · 13 complexity · a2b0f4b60faff2f8c06bc41680ed1f21 MD5 · raw file

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: apt-cacher-ng
  4. # Required-Start: $local_fs $network $remote_fs
  5. # Required-Stop: $local_fs $network $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Apt-Cacher NG package proxy
  9. # Description: This script powers up the package proxy daemon
  10. ### END INIT INFO
  11. # Author: Eduard Bloch <blade@debian.org>
  12. test -r /etc/default/rcS && . /etc/default/rcS
  13. test -r /lib/lsb/init-functions && . /lib/lsb/init-functions
  14. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  15. DAEMON=/usr/sbin/apt-cacher-ng
  16. NAME=apt-cacher-ng
  17. DESC=apt-cacher-ng
  18. test -x $DAEMON || exit 0
  19. # Include apt-cacher-ng defaults if available
  20. if [ -f /etc/default/apt-cacher-ng ] ; then
  21. . /etc/default/apt-cacher-ng
  22. fi
  23. test -z "$DISABLED" || exit 0
  24. # our runtime state files directory, will be purged on startup!
  25. RUNDIR="/var/run/$NAME"
  26. PIDFILE="$RUNDIR/pid"
  27. SOCKETFILE="$RUNDIR/socket"
  28. DAEMON_OPTS="$DAEMON_OPTS pidfile=$PIDFILE SocketPath=$SOCKETFILE foreground=0 $EXTRA_ACNG_OPTS "
  29. do_start() {
  30. PIDOF=$(pidof apt-cacher-ng)
  31. if [ -n "$PIDOF" ] && [ -e "$PIDFILE" ] && [ "$PIDOF" = "$(cat $PIDFILE)" ] ; then
  32. return 255
  33. fi
  34. rm -rf "$RUNDIR" || return 1
  35. install -d --mode=0755 -o $NAME -g $NAME "$RUNDIR" || return 1
  36. start-stop-daemon --start --chuid $NAME --group $NAME --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
  37. }
  38. do_stop() {
  39. if ! start-stop-daemon --stop --retry 15 --quiet --pidfile $PIDFILE \
  40. --exec $DAEMON
  41. then
  42. if ! test -e "$PIDFILE" && ! start-stop-daemon --stop \
  43. --retry TERM/10/KILL/5 --exec $DAEMON
  44. then
  45. return $?
  46. fi
  47. fi
  48. rm -f $PIDFILE
  49. return 0
  50. }
  51. case "$1" in
  52. start)
  53. log_daemon_msg "Starting $DESC" "$NAME"
  54. do_start
  55. log_end_msg $?
  56. ;;
  57. stop)
  58. log_daemon_msg "Stopping $DESC" "$NAME"
  59. do_stop
  60. log_end_msg $?
  61. ;;
  62. restart|force-reload)
  63. log_daemon_msg "Restarting $DESC" "$NAME"
  64. do_stop
  65. do_start
  66. log_end_msg $?
  67. ;;
  68. *)
  69. echo "Usage: $0 {start|stop|restart|force-reload}" >&2
  70. exit 3
  71. ;;
  72. esac
  73. :