decompress_iob(): Make a debug message that isn't supposed to be shown less verbose
[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 script takes care of starting and stopping privoxy.
8 #                 It is supposed to work cross-platform and thus doesn't
9 #                 do too much. When packaging Privoxy it's recommended to
10 #                 write a platform-specific start script instead of using
11 #                 this one.
12 #
13 #  Copyright   :  Written by and Copyright (C) 2001,2002 the
14 #                 Privoxy team. https://www.privoxy.org/
15 #
16 #                 This program is free software; you can redistribute it
17 #                 and/or modify it under the terms of the GNU General
18 #                 Public License as published by the Free Software
19 #                 Foundation; either version 2 of the License, or (at
20 #                 your option) any later version.
21 #
22 #                 This program is distributed in the hope that it will
23 #                 be useful, but WITHOUT ANY WARRANTY; without even the
24 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
25 #                 PARTICULAR PURPOSE.  See the GNU General Public
26 #                 License for more details.
27 #
28 #                 The GNU General Public License should be included with
29 #                 this file.  If not, you can view it at
30 #                 http://www.gnu.org/copyleft/gpl.html
31 #                 or write to the Free Software Foundation, Inc., 59
32 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33 #
34 ###########################################################################
35
36 ### BEGIN INIT INFO
37 # Provides:          privoxy
38 # Required-Start:
39 # Required-Stop:
40 # Default-Start:     2 3 4 5
41 # Default-Stop:      0 1 6
42 # Short-Description: Start privoxy at boot time
43 # Description:       Start and stop the privacy-enhancing HTTP proxy privoxy.
44 ### END INIT INFO
45
46 # NOTE: This script may require editing to ensure proper location of
47 # config file, and the privoxy executable. Care should be taken to ensure
48 # logfile is writable by $P_USER (logfile is defined in config), and that
49 # there is suitable write access for $P_PIDFILE.
50
51 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/xpg4/bin:/usr/bin:/sbin:/bin
52 P_NAME=Privoxy
53 # Path to executable.
54 P_DAEMON=privoxy
55 # Full path to location of Privoxy config file.
56 P_CONF_FILE=/usr/local/etc/privoxy/config
57 # Full path to PID file location. Location must be writable by
58 # whoever runs this script and by Privoxy itself.
59 P_PIDFILE=/var/run/privoxy.pid
60 # If uncommented, this script will try to run as USER=privoxy, which
61 # may require special handling of config, *.action, trust, logfile,
62 # jarfile, and pidfile.
63 P_USER=privoxy
64
65 # If a privoxy user is specified, lets try that. /bin/sh does not seem to
66 # know about $UID.
67 if [ 0 = `id -u` ]; then
68   if [ -n "$P_USER" ]; then
69     id $P_USER 2>/dev/null >/dev/null
70     if [ $? -eq 0 ]; then
71       P_USER_SETTINGS="--user $P_USER"
72     else
73       echo "User $P_USER doesn't exist, exiting."
74       exit 1
75     fi
76   else
77     # The user has sufficient rights, but $P_USER isn't set
78     echo "Running Privoxy as root is not recommended!"
79     P_USER_SETTINGS=""
80   fi
81 else
82   # The user has insufficient rights to run Privoxy as $P_USER
83   # and may not be able to write or delete the PID file.
84   echo "You aren't root, expect trouble!"
85   P_USER_SETTINGS=""
86 fi
87
88 if [ ! -f $P_CONF_FILE ]; then
89   echo "Can't find $P_CONF_FILE, exiting."
90   exit 1
91 fi
92
93 case "$1" in
94
95  start)
96      if [ -f $P_PIDFILE ]; then
97        if kill -0 `cat $P_PIDFILE`; then
98          echo "Error: $P_NAME is already running, exiting."
99          exit 1
100        else
101          rm -f $P_PIDFILE
102        fi
103      fi
104
105         $P_DAEMON --pidfile $P_PIDFILE $P_USER_SETTINGS $P_CONF_FILE 2>/dev/null
106
107      if [ $? -eq 0 ]; then
108        echo "Starting $P_NAME, OK."
109      else
110        echo "Starting $P_NAME, Failed."
111        rm -f $P_PIDFILE
112      fi
113      ;;
114
115  restart)
116      $0 stop
117      $0 start
118      ;;
119
120  stop)
121      test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
122      kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
123      echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
124      ;;
125
126  *)
127      echo "Usage: $0 {start|stop|restart}"
128      exit 1
129      ;;
130
131 esac
132
133 exit 0