Finished verion.
[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: 235 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.
18
19 #  Copyright   :  Written by and Copyright (C) 2001 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.6  2002/03/26 22:29:55  swa
47 #     we have a new homepage!
48 #
49 #     Revision 1.5  2002/03/25 06:14:18  morcego
50 #     Removing the OPRG definition (no longer needed)
51 #
52 #     Revision 1.4  2002/03/25 04:16:48  hal9
53 #     Fix proper config file location.
54 #
55 #     Revision 1.3  2002/03/24 19:12:15  hal9
56 #     Fixed some naming conflicts.
57 #
58 #     Revision 1.2  2002/03/24 11:40:14  swa
59 #     name change
60 #
61 #     Revision 1.1  2002/03/24 11:23:44  swa
62 #     name change
63 #
64 #     Revision 1.1  2002/03/22 20:53:03  morcego
65 #     - Ongoing process to change name to JunkbusterNG
66 #     - configure/configure.in: no change needed
67 #     - GNUmakefile.in:
68 #             - TAR_ARCH = /tmp/JunkbusterNG-$(RPM_VERSION).tar.gz
69 #             - PROGRAM    = jbng@EXEEXT@
70 #             - rh-spec now references as junkbusterng-rh.spec
71 #             - redhat-upload: references changed to junkbusterng-* (package names)
72 #             - tarball-dist: references changed to JunkbusterNG-distribution-*
73 #             - tarball-src: now JunkbusterNG-*
74 #             - install: initscript now junkbusterng.init and junkbusterng (when
75 #                        installed)
76 #     - junkbuster-rh.spec: renamed to junkbusterng-rh.spec
77 #     - junkbusterng.spec:
78 #             - References to the expression ijb where changed where possible
79 #             - New package name: junkbusterng (all in lower case, acording to
80 #               the LSB recomendation)
81 #             - Version changed to: 2.9.13
82 #             - Release: 1
83 #             - Added: junkbuster to obsoletes and conflicts (Not sure this is
84 #               right. If it obsoletes, why conflict ? Have to check it later)
85 #             - Summary changed: Stefan, please check and aprove it
86 #             - Changes description to use the new name
87 #             - Sed string was NOT changed. Have to wait to the manpage to
88 #               change first
89 #             - Keeping the user junkbuster for now. It will require some aditional
90 #               changes on the script (scheduled for the next specfile release)
91 #             - Added post entry to move the old logfile to the new log directory
92 #             - Removing "chkconfig --add" entry (not good to have it automaticaly
93 #               added to the startup list).
94 #             - Added preun section to stop the service with the old name, as well
95 #               as remove it from the startup list
96 #             - Removed the chkconfig --del entry from the conditional block on
97 #               the preun scriptlet (now handled on the %files section)
98 #     - junkbuster.init: renamed to junkbusterng.init
99 #     - junkbusterng.init:
100 #             - Changed JB_BIN to jbng
101 #             - Created JB_OBIN with the old value of JB_BIN (junkbuster), to
102 #               be used where necessary (config dir)
103 #
104 #     Aditional notes:
105 #     - The config directory is /etc/junkbuster yet. Have to change it on the
106 #     specfile, after it is changes on the code
107 #     - The only files that got renamed on the cvs tree were the rh specfile and
108 #     the init file. Some file references got changes on the makefile and on the
109 #     rh-spec (as listed above)
110 #
111 #     Revision 1.15  2002/03/09 15:05:58  swa
112 #     wrong user.group
113 #
114 #     Revision 1.14  2002/03/06 06:13:40  hal9
115 #     Adapted for Andreas' changes for --user and --pidfile.
116 #
117 #     Revision 1.13  2002/03/05 05:10:10  oes
118 #     Changed pidfile path to conform with FHS
119 #
120 #     Revision 1.12  2002/03/04 20:44:36  oes
121 #     Changed to new cmdline syntax
122 #
123 #     Revision 1.11  2001/12/30 14:07:32  steudten
124 #     - Add signal handling (unix)
125 #     - Add SIGHUP handler (unix)
126 #     - Add creation of pidfile (unix)
127 #     - Add action 'top' in rc file (RH)
128 #     - Add entry 'SIGNALS' to manpage
129 #     - Add exit message to logfile (unix)
130 #
131 #     Revision 1.10  2001/11/05 21:30:23  steudten
132 #     Make JB startup without & due to be a 'real' daemon right now.
133 #     Make the script easy to change.
134 #
135 #     Revision 1.9  2001/09/15 01:53:12  steudten
136 #
137 #     Remove test for subsys flag in start. Some minor changes.
138 #
139 #     Revision 1.8  2001/06/28 13:50:36  sarantis
140 #     swap ?$ with $?; remove bogus ";;"
141 #
142 #     Revision 1.7  2001/06/28 13:40:26  sarantis
143 #     remove single quotes from $JB; it was not expanded.
144 #
145 #     Revision 1.6  2001/06/28 13:38:42  sarantis
146 #     formatting changes; individual return values are returned from the init script.
147 #
148 #     Revision 1.5  2001/06/11 11:37:40  sarantis
149 #     Minor editing changes.
150 #
151 #     Revision 1.4  2001/06/09 09:14:11  swa
152 #     shamelessly adapted RPM stuff from the newest rpm that
153 #     RedHat provided for the JB.
154 #
155 #     Revision 1.3  2001/05/25 10:12:44  oes
156 #     Fixed default case in switch statement (# -> *)
157 #
158 #     Revision 1.2  2001/05/24 07:52:24  swa
159 #     added header. removed ^M.
160 #
161
162 # ********************************************************************/
163
164
165 # Source function library.
166 . /etc/rc.d/init.d/functions
167
168 . /etc/sysconfig/network
169
170 #  Check that networking is up.
171 [ ${NETWORKING} = "no" ] && exit 0
172
173 JB_PRG="privoxy"
174 JB_BIN="/usr/sbin/$JB_PRG"
175 JB_CONF="/etc/$JB_PRG/config"
176 JB_USER="privoxy"
177 JB_PID=/var/run/$JB_PRG.pid
178 JB_LOCK=/var/lock/subsys/$JB_PRG
179 JB="$JB_BIN --user $JB_USER.$JB_USER --pidfile $JB_PID $JB_CONF"
180
181 # some checks for us
182 ! [ -x $JB_BIN  ] && echo "Can't find $JB_BIN, exit." && exit 0
183 ! [ -f $JB_CONF ] && echo "Can't find $JB_CONF, exit." && exit 0
184
185 # See how we were called.
186
187 start () {
188         # start daemon
189         echo -n $"Starting $JB_PRG: "
190      if [ -f $JB_PID ]; then 
191         killproc $JB_PRG && rm -f $JB_LOCK $JB_PID
192         RETVAL=$?
193         [ $RETVAL != 0 ] && return $RETVAL
194      fi
195         daemon $JB 
196         RETVAL=$?
197         echo
198         [ $RETVAL = 0 ] && touch $JB_LOCK
199         return $RETVAL
200 }
201
202 stop () {
203         # stop daemon
204         echo -n $"Stopping $JB_PRG: "
205         killproc $JB_PRG && rm -f $JB_LOCK $JB_PID
206         RETVAL=$?
207         echo
208         return $RETVAL
209 }
210
211 case "$1" in
212   start)
213         start   
214         ;;
215   stop)
216         stop
217         ;;
218   reload)
219         if [ -f $JB_PID ] ; then
220         kill -HUP `cat $JB_PID`
221         RETVAL=$?
222      fi
223         ;;
224   restart)
225         stop
226         start
227         RETVAL=$?
228         ;;
229   condrestart)
230         # restart only if already running
231         if [ -f $JB_PID ] ; then
232         stop
233         start
234         RETVAL=$?
235         fi 
236         ;;
237   status)
238         status $JB_PRG 
239         RETVAL=$?
240         ;;
241   top)
242      if [ -f $JB_PID ]; then
243                 a=""
244                 for i in `pidof $JB_PRG` ; do
245                         a="$a -p $i"
246                 done
247                 top $a
248      fi
249         ;;
250   *)
251         echo $"Usage: $JB_PRG {start|stop|reload|restart|condrestart|status|top}"
252         exit 1
253 esac
254
255 exit $RETVAL