Time flies :)
[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.5  2002/10/17 17:01:29  hal9
43 #     Set paths to match the defaults for a root install. Force remove PIDFILE on
44 #     stop.
45 #
46 #     Revision 1.4  2002/09/11 01:15:02  hal9
47 #     Fix typo in variable. Now tested on Solaris and Linux, with defaults.
48 #
49 #     Revision 1.3  2002/09/11 01:09:14  hal9
50 #     Better handling of pidfile, and process owner.
51 #
52 #     Revision 1.2  2002/09/08 20:27:58  hal9
53 #     -Rewrote script config section.
54 #     -Added comments to script.
55 #     -Tried to add logic to use a --user privoxy, if available.
56 #     -Minor script changes due to 'echo -n' does not work on a true
57 #      /bin/sh system.
58 #
59 #     Revision 1.1  2002/09/06 00:20:26  hal9
60 #     Creating a generic init script, meant to be used on platforms where don't have
61 #     a custom init script.
62 #
63 #     Revision 1.0  2002/09/05 17:14:32  hal9
64 #
65 #######################################################################
66
67 # Is this needed by Solaris?
68 #ident  "@(#)privoxy  1.0     02/09/05"
69
70 # NOTE: This script may require editing to ensure proper location of 
71 # config file, and the privoxy executable. Care should be taken to ensure 
72 # logfile is writable by $P_USER (logfile is defined in config), and that 
73 # there is suitable write access for $P_PIDFILE.
74
75 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/sbin:/bin
76 P_NAME=Privoxy
77 # Path to executable.
78 P_DAEMON=privoxy
79 # Full path to location of Privoxy config file. 
80 P_CONF_FILE=/usr/local/etc/privoxy/config
81 # Full path to PID file location. Location must be writable by 
82 # whoever runs this script.
83 P_PIDFILE=/var/run/privoxy.pid
84 # If uncommented, this script will try to run as USER=privoxy, which
85 # may require special handling of config, *.action, trust, logfile, 
86 # jarfile, and pidfile.
87 P_USER=privoxy
88
89 # If a privoxy user is specified, lets try that. /bin/sh does not seem to 
90 # know about $UID.
91 if [ "$USER" = "root" ] && [ -n "$P_USER" ] && id $P_USER >/dev/null; then
92   P_OWNER=$P_USER
93 else 
94   P_OWNER=$USER
95 fi
96
97 if [ ! -f $P_CONF_FILE ]; then
98   echo "Can't find $P_CONF_FILE, exiting."
99   exit 1
100 fi
101
102 case "$1" in
103  
104  start)
105      if [ -f $P_PIDFILE ]; then
106        if kill -0 `cat $P_PIDFILE`; then
107          echo "Error: $P_NAME is already running, exiting."
108          exit 1
109        else
110          rm -f $P_PIDFILE
111        fi
112      fi
113
114         $P_DAEMON --pidfile $P_PIDFILE --user $P_OWNER $P_CONF_FILE 2>/dev/null
115      
116      if [ $? -eq 0 ]; then
117        echo "Starting $P_NAME, OK." 
118      else
119        echo "Starting $P_NAME, Failed."
120        rm -f $P_PIDFILE
121      fi
122      ;;
123  
124  restart)
125      $0 stop
126      $0 start
127      ;;
128  
129  stop)
130      test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
131      kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
132      echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
133      ;;
134  
135  *)
136      echo "Usage: $0 {start|stop|restart}"
137      exit 1
138      ;;
139
140 esac
141
142 exit 0