Added check for timegm().
[privoxy.git] / slackware / rc.privoxy.orig
1 #!/bin/sh
2 #  ********************************************************************
3
4 RETVAL=1
5
6 PRIVOXY_PRG="%PROGRAM%"
7 PRIVOXY_BIN="%SBIN_DEST%/$PRIVOXY_PRG"
8 PRIVOXY_CONF="%CONF_DEST%/config"
9 PRIVOXY_USER="%USER%"
10 PRIVOXY_GROUP="%GROUP%"
11 PRIVOXY_PID="/var/run/$PRIVOXY_PRG"/$PRIVOXY_PRG.pid
12
13 declare -i check
14 check=(`/bin/ps -e|/bin/grep $PRIVOXY_PRG|/usr/bin/wc -l`)
15
16 # some checks for us
17 if [ ! -x $PRIVOXY_BIN  ] ; then exit 0 ;fi
18 if [ ! -f $PRIVOXY_CONF ] ; then exit 0 ;fi
19
20 # See how we were called.
21
22 PRIVOXY="$PRIVOXY_BIN $PRIVOXY_CONF"
23
24 start () {
25         # start daemon
26         echo -n $"Starting $PRIVOXY_PRG: "
27
28         if [ ! -f $PRIVOXY_PID ]; then
29                 ($PRIVOXY --user $PRIVOXY_USER.$PRIVOXY_GROUP  --pidfile $PRIVOXY_PID 2>/dev/tty9 ) \
30                         && echo " OK" \
31                         && /bin/touch /var/lock/$PRIVOXY_PRG \
32                         && RETVAL=0
33         elif [ $check -lt 3 ]; then 
34                 echo "Zombie lock file found"
35                 /bin/rm -f /var/lock/$PRIVOXY_PRG $PRIVOXY_PID
36                 echo "Retrying..."
37                 start
38         else
39                 echo "Already running"
40         fi
41         echo
42 }
43
44 stop () {
45         # stop daemon
46         echo -n $"Stopping $PRIVOXY_PRG: "
47         if [ -f $PRIVOXY_PID ]; then
48                 /bin/kill `/bin/cat $PRIVOXY_PID` \
49                         && /bin/rm -f /var/lock/$PRIVOXY_PRG $PRIVOXY_PID \
50                         && echo " OK" \
51                         && RETVAL=0
52                 echo
53         else
54                 echo " Not Running"
55         fi
56 }
57
58 case "$1" in
59   start)
60         start   
61         ;;
62   stop)
63         stop    
64         ;;
65   reload)
66         if [ -f $PRIVOXY_PID ] ; then
67                 /bin/kill -HUP `cat $PRIVOXY_PID` \
68                         && RETVAL=0
69         fi
70         ;;
71   restart)
72         stop 
73         start
74         ;;
75   kill)
76         echo "Kill all Privoxy"
77         /bin/rm -f /var/lock/$PRIVOXY_PRG $PRIVOXY_PID 
78         /bin/killall $PRIVOXY
79         ;;
80   condrestart)
81         # restart only if already running
82         if [ -f $PRIVOXY_PID ] ; then
83                 stop
84                 start
85         fi 
86         ;;
87   status)
88         /bin/ps ax|/bin/grep $PRIVOXY_PRG|/bin/grep -v 'grep\|init\.d\|rc\.d'
89         RETVAL=0
90         ;;
91   top)
92         if [ -f $PRIVOXY_PID ]; then
93                 a=""
94                 for i in `/sbin/pidof $PRIVOXY_PRG` ; do
95                         a="$a -p $i"
96                 done
97                 /usr/bin/top $a
98         fi
99         ;;
100   *)
101         echo $"Usage: $PRIVOXY_PRG {start|stop|reload|restart|condrestart|status|top|kill}"
102         exit 1
103 esac
104
105 exit $RETVAL