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