Call initialize_mutexes() before init_log_module() again.
[privoxy.git] / privoxy-generic.init
1 #!/bin/sh 
2
3 #  ********************************************************************
4
5 #  File        :  $Source: /cvsroot/ijbswa/current/privoxy-generic.init,v $
6
7 #  Purpose     :  This shell script takes care of starting and stopping
8 #                 privoxy.
9
10 #  Copyright   :  Written by and Copyright (C) 2001,2002 the SourceForge
11 #                 Privoxy team. http://www.privoxy.org/
12
13 #                 Based on the Internet Junkbuster originally written
14 #                 by and Copyright (C) 1997 Anonymous Coders and
15 #                 Junkbusters Corporation.  http://www.junkbusters.com
16
17 #                 This program is free software; you can redistribute it
18 #                 and/or modify it under the terms of the GNU General
19 #                 Public License as published by the Free Software
20 #                 Foundation; either version 2 of the License, or (at
21 #                 your option) any later version.
22
23 #                 This program is distributed in the hope that it will
24 #                 be useful, but WITHOUT ANY WARRANTY; without even the
25 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
26 #                 PARTICULAR PURPOSE.  See the GNU General Public
27 #                 License for more details.
28
29 #                 The GNU General Public License should be included with
30 #                 this file.  If not, you can view it at
31 #                 http://www.gnu.org/copyleft/gpl.html
32 #                 or write to the Free Software Foundation, Inc., 59
33 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34 #
35 # Developer's NOTE: This script should be tested against a true /bin/sh, which
36 # has notable differences from bash. By design, this script does not try to do
37 # too much, so as to be as cross-platform as possible.
38 #
39
40 #  Revisions   :
41 #     $Log: privoxy-generic.init,v $
42 #     Revision 1.7  2006/10/14 14:12:22  fabiankeil
43 #     Print warnings if the user tries to run Privoxy as root
44 #     or if the script is run without root privileges;
45 #     only use "--user" if run with root privileges and
46 #     don't depend on $USER being set to root. Fixes BR 779781.
47 #
48 #     Apparently $USER isn't set on all systems,
49 #     but it also didn't work if the user only
50 #     increased her privileges with su or sudo,
51 #     but still had her real uid in $USER.
52 #
53 #     Thanks to Florian Effenberger for reporting.
54 #
55 #     Revision 1.6  2006/07/18 14:48:47  david__schmidt
56 #     Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
57 #     with what was really the latest development (the v_3_0_branch branch)
58 #
59 #     Revision 1.5.2.1  2002/10/17 17:04:22  hal9
60 #     Add from main trunk. Will be needed for make install.
61 #
62 #     Revision 1.5  2002/10/17 17:01:29  hal9
63 #     Set paths to match the defaults for a root install. Force remove PIDFILE on
64 #     stop.
65 #
66 #     Revision 1.4  2002/09/11 01:15:02  hal9
67 #     Fix typo in variable. Now tested on Solaris and Linux, with defaults.
68 #
69 #     Revision 1.3  2002/09/11 01:09:14  hal9
70 #     Better handling of pidfile, and process owner.
71 #
72 #     Revision 1.2  2002/09/08 20:27:58  hal9
73 #     -Rewrote script config section.
74 #     -Added comments to script.
75 #     -Tried to add logic to use a --user privoxy, if available.
76 #     -Minor script changes due to 'echo -n' does not work on a true
77 #      /bin/sh system.
78 #
79 #     Revision 1.1  2002/09/06 00:20:26  hal9
80 #     Creating a generic init script, meant to be used on platforms where don't have
81 #     a custom init script.
82 #
83 #     Revision 1.0  2002/09/05 17:14:32  hal9
84 #
85 #######################################################################
86
87 # Is this needed by Solaris?
88 #ident  "@(#)privoxy  1.0     02/09/05"
89
90 # NOTE: This script may require editing to ensure proper location of 
91 # config file, and the privoxy executable. Care should be taken to ensure 
92 # logfile is writable by $P_USER (logfile is defined in config), and that 
93 # there is suitable write access for $P_PIDFILE.
94
95 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/xpg4/bin:/usr/bin:/sbin:/bin
96 P_NAME=Privoxy
97 # Path to executable.
98 P_DAEMON=privoxy
99 # Full path to location of Privoxy config file. 
100 P_CONF_FILE=/usr/local/etc/privoxy/config
101 # Full path to PID file location. Location must be writable by 
102 # whoever runs this script and by Privoxy itself.
103 P_PIDFILE=/var/run/privoxy.pid
104 # If uncommented, this script will try to run as USER=privoxy, which
105 # may require special handling of config, *.action, trust, logfile, 
106 # jarfile, and pidfile.
107 P_USER=privoxy
108
109 # If a privoxy user is specified, lets try that. /bin/sh does not seem to 
110 # know about $UID.
111 if [ 0 = `id -u` ]; then
112   if [ -n "$P_USER" ]; then
113     id $P_USER 2>/dev/null >/dev/null
114     if [ $? -eq 0 ]; then
115       P_USER_SETTINGS="--user $P_USER"
116     else
117       echo "User $P_USER doesn't exist, exiting."
118       exit 1
119     fi 
120   else
121     # The user has sufficient rights, but $P_USER isn't set
122     echo "Running Privoxy as root is not recommended!" 
123     P_USER_SETTINGS=""
124   fi
125 else
126   # The user has insufficient rights to run Privoxy as $P_USER
127   # and may not be able to write or delete the PID file.
128   echo "You aren't root, expect trouble!"
129   P_USER_SETTINGS=""
130 fi
131
132 if [ ! -f $P_CONF_FILE ]; then
133   echo "Can't find $P_CONF_FILE, exiting."
134   exit 1
135 fi
136
137 case "$1" in
138  
139  start)
140      if [ -f $P_PIDFILE ]; then
141        if kill -0 `cat $P_PIDFILE`; then
142          echo "Error: $P_NAME is already running, exiting."
143          exit 1
144        else
145          rm -f $P_PIDFILE
146        fi
147      fi
148
149         $P_DAEMON --pidfile $P_PIDFILE $P_USER_SETTINGS $P_CONF_FILE 2>/dev/null
150      
151      if [ $? -eq 0 ]; then
152        echo "Starting $P_NAME, OK." 
153      else
154        echo "Starting $P_NAME, Failed."
155        rm -f $P_PIDFILE
156      fi
157      ;;
158  
159  restart)
160      $0 stop
161      $0 start
162      ;;
163  
164  stop)
165      test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
166      kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
167      echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
168      ;;
169  
170  *)
171      echo "Usage: $0 {start|stop|restart}"
172      exit 1
173      ;;
174
175 esac
176
177 exit 0