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