-#!/bin/sh
+#!/bin/sh
#
# ********************************************************************
#
-# File : $Source: /cvsroot/ijbswa/current/privoxy.init,v $
+# File : $Source: /cvsroot/ijbswa/current/privoxy-generic.init,v $
#
# Purpose : This shell script takes care of starting and stopping
# privoxy.
# http://www.gnu.org/copyleft/gpl.html
# or write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Developer's NOTE: This script should be tested against a true /bin/sh, which
+# has notable differences from bash. By design, this script does not try to do
+# too much, so as to be as cross-platform as possible.
+#
#
# Revisions :
# $Log: privoxy-generic.init,v $
+# Revision 1.5.2.1 2002/10/17 17:04:22 hal9
+# Add from main trunk. Will be needed for make install.
+#
+# Revision 1.5 2002/10/17 17:01:29 hal9
+# Set paths to match the defaults for a root install. Force remove PIDFILE on
+# stop.
+#
+# Revision 1.4 2002/09/11 01:15:02 hal9
+# Fix typo in variable. Now tested on Solaris and Linux, with defaults.
+#
+# Revision 1.3 2002/09/11 01:09:14 hal9
+# Better handling of pidfile, and process owner.
+#
+# Revision 1.2 2002/09/08 20:27:58 hal9
+# -Rewrote script config section.
+# -Added comments to script.
+# -Tried to add logic to use a --user privoxy, if available.
+# -Minor script changes due to 'echo -n' does not work on a true
+# /bin/sh system.
+#
+# Revision 1.1 2002/09/06 00:20:26 hal9
+# Creating a generic init script, meant to be used on platforms where don't have
+# a custom init script.
+#
# Revision 1.0 2002/09/05 17:14:32 hal9
#
#######################################################################
# Is this needed by Solaris?
#ident "@(#)privoxy 1.0 02/09/05"
+# NOTE: This script may require editing to ensure proper location of
+# config file, and the privoxy executable. Care should be taken to ensure
+# logfile is writable by $P_USER (logfile is defined in config), and that
+# there is suitable write access for $P_PIDFILE.
+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/sbin:/bin
-NAME=Privoxy
-DAEMON=privoxy
-P_CONF_FILE=/etc/${NAME}/config
-PIDFILE=/var/run/${NAME}.pid
-#RUN_AS="--user privoxy"
+P_NAME=Privoxy
+# Path to executable.
+P_DAEMON=privoxy
+# Full path to location of Privoxy config file.
+P_CONF_FILE=/usr/local/etc/privoxy/config
+# Full path to PID file location. Location must be writable by
+# whoever runs this script.
+P_PIDFILE=/var/run/privoxy.pid
+# If uncommented, this script will try to run as USER=privoxy, which
+# may require special handling of config, *.action, trust, logfile,
+# jarfile, and pidfile.
+P_USER=privoxy
+
+# If a privoxy user is specified, lets try that. /bin/sh does not seem to
+# know about $UID.
+if [ "$USER" = "root" ] && [ -n "$P_USER" ] && id $P_USER >/dev/null; then
+ P_OWNER=$P_USER
+else
+ P_OWNER=$USER
+fi
if [ ! -f $P_CONF_FILE ]; then
echo "Can't find $P_CONF_FILE, exiting."
case "$1" in
start)
- test -f $PIDFILE && echo "$PIDFILE exists, exiting." && exit 1
- echo -n "Starting $NAME: "
- $DAEMON --pidfile $PIDFILE $RUN_AS $P_CONF_FILE 2>/dev/null &&\
- echo "OK." || echo "Failed."
-
+ if [ -f $P_PIDFILE ]; then
+ if kill -0 `cat $P_PIDFILE`; then
+ echo "Error: $P_NAME is already running, exiting."
+ exit 1
+ else
+ rm -f $P_PIDFILE
+ fi
+ fi
+
+ $P_DAEMON --pidfile $P_PIDFILE --user $P_OWNER $P_CONF_FILE 2>/dev/null
+
+ if [ $? -eq 0 ]; then
+ echo "Starting $P_NAME, OK."
+ else
+ echo "Starting $P_NAME, Failed."
+ rm -f $P_PIDFILE
+ fi
;;
restart)
;;
stop)
- echo -n "Stopping $NAME: "
- kill `cat $PIDFILE` &&\
- echo "OK." || echo "Failed."
+ test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
+ kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
+ echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
+
esac
exit 0