PageRenderTime 78ms CodeModel.GetById 74ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 1ms

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