Add Mattes, Johny, Brian.
[privoxy.git] / privoxy.init
1 #!/bin/sh
2 #
3 # This is file /etc/rc.d/init.d/privoxy and was put here 
4 # by the privoxy rpm
5 #
6 # chkconfig: 2345 84 09
7 #
8 # description: This shell script takes care of starting and stopping \
9 #              privoxy.
10 #
11
12 #  ********************************************************************
13
14 #  File        :  $Source: /cvsroot/ijbswa/current/privoxy.init,v $
15
16 #  Purpose     :  This shell script takes care of starting and stopping
17 #                 privoxy on Red Hat and RH compatible systems.
18
19 #  Copyright   :  Written by and Copyright (C) 2001,2002 the SourceForge
20 #                 Privoxy team. http://www.privoxy.org/
21
22 #                 Based on the Internet Junkbuster originally written
23 #                 by and Copyright (C) 1997 Anonymous Coders and
24 #                 Junkbusters Corporation.  http://www.junkbusters.com
25
26 #                 This program is free software; you can redistribute it
27 #                 and/or modify it under the terms of the GNU General
28 #                 Public License as published by the Free Software
29 #                 Foundation; either version 2 of the License, or (at
30 #                 your option) any later version.
31
32 #                 This program is distributed in the hope that it will
33 #                 be useful, but WITHOUT ANY WARRANTY; without even the
34 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
35 #                 PARTICULAR PURPOSE.  See the GNU General Public
36 #                 License for more details.
37
38 #                 The GNU General Public License should be included with
39 #                 this file.  If not, you can view it at
40 #                 http://www.gnu.org/copyleft/gpl.html
41 #                 or write to the Free Software Foundation, Inc., 59
42 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
43
44 #  Revisions   :
45 #     $Log: privoxy.init,v $
46 #     Revision 1.9  2002/09/05 15:38:30  oes
47 #     Synced with the stable branch:
48 #        Revision 1.8.2.2  2002/08/05 08:42:13  kick_
49 #        same permissions, same runlevels as all the other initscripts
50 #
51 #        Revision 1.8.2.1  2002/07/12 09:14:26  kick_
52 #        don't use ghost files for rcX.d/*, chkconfig is available to do this job. Enable translation of error messge
53 #
54 #     Revision 1.8  2002/04/09 02:51:31  hal9
55 #     Changed $JB to $PRIVOXY.
56 #
57 #     Revision 1.7  2002/04/08 14:54:51  morcego
58 #     Moved the chkconfig comments to the begining of the file, couse Linuxconf
59 #     was getting confused with it where it was.
60 #
61 #     Revision 1.6  2002/03/26 22:29:55  swa
62 #     we have a new homepage!
63 #
64 #     Revision 1.5  2002/03/25 06:14:18  morcego
65 #     Removing the OPRG definition (no longer needed)
66 #
67 #     Revision 1.4  2002/03/25 04:16:48  hal9
68 #     Fix proper config file location.
69 #
70 #     Revision 1.3  2002/03/24 19:12:15  hal9
71 #     Fixed some naming conflicts.
72 #
73 #     Revision 1.2  2002/03/24 11:40:14  swa
74 #     name change
75 #
76 #     Revision 1.1  2002/03/24 11:23:44  swa
77 #     name change
78 #
79 #     Revision 1.1  2002/03/22 20:53:03  morcego
80 #     - Ongoing process to change name to JunkbusterNG
81 #     - configure/configure.in: no change needed
82 #     - GNUmakefile.in:
83 #             - TAR_ARCH = /tmp/JunkbusterNG-$(RPM_VERSION).tar.gz
84 #             - PROGRAM    = jbng@EXEEXT@
85 #             - rh-spec now references as junkbusterng-rh.spec
86 #             - redhat-upload: references changed to junkbusterng-* (package names)
87 #             - tarball-dist: references changed to JunkbusterNG-distribution-*
88 #             - tarball-src: now JunkbusterNG-*
89 #             - install: initscript now junkbusterng.init and junkbusterng (when
90 #                        installed)
91 #     - junkbuster-rh.spec: renamed to junkbusterng-rh.spec
92 #     - junkbusterng.spec:
93 #             - References to the expression ijb where changed where possible
94 #             - New package name: junkbusterng (all in lower case, acording to
95 #               the LSB recomendation)
96 #             - Version changed to: 2.9.13
97 #             - Release: 1
98 #             - Added: junkbuster to obsoletes and conflicts (Not sure this is
99 #               right. If it obsoletes, why conflict ? Have to check it later)
100 #             - Summary changed: Stefan, please check and aprove it
101 #             - Changes description to use the new name
102 #             - Sed string was NOT changed. Have to wait to the manpage to
103 #               change first
104 #             - Keeping the user junkbuster for now. It will require some aditional
105 #               changes on the script (scheduled for the next specfile release)
106 #             - Added post entry to move the old logfile to the new log directory
107 #             - Removing "chkconfig --add" entry (not good to have it automaticaly
108 #               added to the startup list).
109 #             - Added preun section to stop the service with the old name, as well
110 #               as remove it from the startup list
111 #             - Removed the chkconfig --del entry from the conditional block on
112 #               the preun scriptlet (now handled on the %files section)
113 #     - junkbuster.init: renamed to junkbusterng.init
114 #     - junkbusterng.init:
115 #             - Changed JB_BIN to jbng
116 #             - Created JB_OBIN with the old value of JB_BIN (junkbuster), to
117 #               be used where necessary (config dir)
118 #
119 #     Aditional notes:
120 #     - The config directory is /etc/junkbuster yet. Have to change it on the
121 #     specfile, after it is changes on the code
122 #     - The only files that got renamed on the cvs tree were the rh specfile and
123 #     the init file. Some file references got changes on the makefile and on the
124 #     rh-spec (as listed above)
125 #
126 #     Revision 1.15  2002/03/09 15:05:58  swa
127 #     wrong user.group
128 #
129 #     Revision 1.14  2002/03/06 06:13:40  hal9
130 #     Adapted for Andreas' changes for --user and --pidfile.
131 #
132 #     Revision 1.13  2002/03/05 05:10:10  oes
133 #     Changed pidfile path to conform with FHS
134 #
135 #     Revision 1.12  2002/03/04 20:44:36  oes
136 #     Changed to new cmdline syntax
137 #
138 #     Revision 1.11  2001/12/30 14:07:32  steudten
139 #     - Add signal handling (unix)
140 #     - Add SIGHUP handler (unix)
141 #     - Add creation of pidfile (unix)
142 #     - Add action 'top' in rc file (RH)
143 #     - Add entry 'SIGNALS' to manpage
144 #     - Add exit message to logfile (unix)
145 #
146 #     Revision 1.10  2001/11/05 21:30:23  steudten
147 #     Make JB startup without & due to be a 'real' daemon right now.
148 #     Make the script easy to change.
149 #
150 #     Revision 1.9  2001/09/15 01:53:12  steudten
151 #
152 #     Remove test for subsys flag in start. Some minor changes.
153 #
154 #     Revision 1.8  2001/06/28 13:50:36  sarantis
155 #     swap ?$ with $?; remove bogus ";;"
156 #
157 #     Revision 1.7  2001/06/28 13:40:26  sarantis
158 #     remove single quotes from $JB; it was not expanded.
159 #
160 #     Revision 1.6  2001/06/28 13:38:42  sarantis
161 #     formatting changes; individual return values are returned from the init script.
162 #
163 #     Revision 1.5  2001/06/11 11:37:40  sarantis
164 #     Minor editing changes.
165 #
166 #     Revision 1.4  2001/06/09 09:14:11  swa
167 #     shamelessly adapted RPM stuff from the newest rpm that
168 #     RedHat provided for the JB.
169 #
170 #     Revision 1.3  2001/05/25 10:12:44  oes
171 #     Fixed default case in switch statement (# -> *)
172 #
173 #     Revision 1.2  2001/05/24 07:52:24  swa
174 #     added header. removed ^M.
175 #
176
177 # ********************************************************************/
178
179
180 # Source function library.
181 . /etc/rc.d/init.d/functions
182
183 . /etc/sysconfig/network
184
185 #  Check that networking is up.
186 [ ${NETWORKING} = "no" ] && exit 0
187
188 PRIVOXY_PRG="privoxy"
189 PRIVOXY_BIN="/usr/sbin/$PRIVOXY_PRG"
190 PRIVOXY_CONF="/etc/$PRIVOXY_PRG/config"
191 PRIVOXY_USER="privoxy"
192 PRIVOXY_PID=/var/run/$PRIVOXY_PRG.pid
193 PRIVOXY_LOCK=/var/lock/subsys/$PRIVOXY_PRG
194 PRIVOXY="$PRIVOXY_BIN --user $PRIVOXY_USER.$PRIVOXY_USER --pidfile $PRIVOXY_PID $PRIVOXY_CONF"
195
196 # some checks for us
197 ! [ -x $PRIVOXY_BIN  ] && echo $"Can't find $PRIVOXY_BIN, exit." && exit 0
198 ! [ -f $PRIVOXY_CONF ] && echo $"Can't find $PRIVOXY_CONF, exit." && exit 0
199
200 # See how we were called.
201
202 start () {
203         # start daemon
204         echo -n $"Starting $PRIVOXY_PRG: "
205      if [ -f $PRIVOXY_PID ]; then 
206         killproc $PRIVOXY_PRG && rm -f $PRIVOXY_LOCK $PRIVOXY_PID
207         RETVAL=$?
208         [ $RETVAL != 0 ] && return $RETVAL
209      fi
210         daemon $PRIVOXY
211         RETVAL=$?
212         echo
213         [ $RETVAL = 0 ] && touch $PRIVOXY_LOCK
214         return $RETVAL
215 }
216
217 stop () {
218         # stop daemon
219         echo -n $"Stopping $PRIVOXY_PRG: "
220         killproc $PRIVOXY_PRG && rm -f $PRIVOXY_LOCK $PRIVOXY_PID
221         RETVAL=$?
222         echo
223         return $RETVAL
224 }
225
226 case "$1" in
227   start)
228         start   
229         ;;
230   stop)
231         stop
232         ;;
233   reload)
234         if [ -f $PRIVOXY_PID ] ; then
235         kill -HUP `cat $PRIVOXY_PID`
236         RETVAL=$?
237      fi
238         ;;
239   restart)
240         stop
241         start
242         RETVAL=$?
243         ;;
244   condrestart)
245         # restart only if already running
246         if [ -f $PRIVOXY_PID ] ; then
247         stop
248         start
249         RETVAL=$?
250         fi 
251         ;;
252   status)
253         status $PRIVOXY_PRG 
254         RETVAL=$?
255         ;;
256   top)
257      if [ -f $PRIVOXY_PID ]; then
258                 a=""
259                 for i in `pidof $PRIVOXY_PRG` ; do
260                         a="$a -p $i"
261                 done
262                 top $a
263      fi
264         ;;
265   *)
266         echo $"Usage: $PRIVOXY_PRG {start|stop|reload|restart|condrestart|status|top}"
267         exit 1
268 esac
269
270 exit $RETVAL