Don't bother trying to continue chatting if the client didn't ask for it.
[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
41 # Is this needed by Solaris?
42 #ident  "@(#)privoxy  1.0     02/09/05"
43
44 # NOTE: This script may require editing to ensure proper location of 
45 # config file, and the privoxy executable. Care should be taken to ensure 
46 # logfile is writable by $P_USER (logfile is defined in config), and that 
47 # there is suitable write access for $P_PIDFILE.
48
49 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/xpg4/bin:/usr/bin:/sbin:/bin
50 P_NAME=Privoxy
51 # Path to executable.
52 P_DAEMON=privoxy
53 # Full path to location of Privoxy config file. 
54 P_CONF_FILE=/usr/local/etc/privoxy/config
55 # Full path to PID file location. Location must be writable by 
56 # whoever runs this script and by Privoxy itself.
57 P_PIDFILE=/var/run/privoxy.pid
58 # If uncommented, this script will try to run as USER=privoxy, which
59 # may require special handling of config, *.action, trust, logfile, 
60 # jarfile, and pidfile.
61 P_USER=privoxy
62
63 # If a privoxy user is specified, lets try that. /bin/sh does not seem to 
64 # know about $UID.
65 if [ 0 = `id -u` ]; then
66   if [ -n "$P_USER" ]; then
67     id $P_USER 2>/dev/null >/dev/null
68     if [ $? -eq 0 ]; then
69       P_USER_SETTINGS="--user $P_USER"
70     else
71       echo "User $P_USER doesn't exist, exiting."
72       exit 1
73     fi 
74   else
75     # The user has sufficient rights, but $P_USER isn't set
76     echo "Running Privoxy as root is not recommended!" 
77     P_USER_SETTINGS=""
78   fi
79 else
80   # The user has insufficient rights to run Privoxy as $P_USER
81   # and may not be able to write or delete the PID file.
82   echo "You aren't root, expect trouble!"
83   P_USER_SETTINGS=""
84 fi
85
86 if [ ! -f $P_CONF_FILE ]; then
87   echo "Can't find $P_CONF_FILE, exiting."
88   exit 1
89 fi
90
91 case "$1" in
92  
93  start)
94      if [ -f $P_PIDFILE ]; then
95        if kill -0 `cat $P_PIDFILE`; then
96          echo "Error: $P_NAME is already running, exiting."
97          exit 1
98        else
99          rm -f $P_PIDFILE
100        fi
101      fi
102
103         $P_DAEMON --pidfile $P_PIDFILE $P_USER_SETTINGS $P_CONF_FILE 2>/dev/null
104      
105      if [ $? -eq 0 ]; then
106        echo "Starting $P_NAME, OK." 
107      else
108        echo "Starting $P_NAME, Failed."
109        rm -f $P_PIDFILE
110      fi
111      ;;
112  
113  restart)
114      $0 stop
115      $0 start
116      ;;
117  
118  stop)
119      test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
120      kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
121      echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
122      ;;
123  
124  *)
125      echo "Usage: $0 {start|stop|restart}"
126      exit 1
127      ;;
128
129 esac
130
131 exit 0