X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=privoxy-generic.init;h=ac5123443ebd501c5477c5770308ef6d91c89ec5;hp=74e25d9032c7cf7082e0d3ac252c14fb180a6c0e;hb=7ae12b2afe7124cc23216f76aec2acdd5c085595;hpb=c9239ae9826b7dedb7da316db1c74663d5a584b5 diff --git a/privoxy-generic.init b/privoxy-generic.init index 74e25d90..ac512344 100755 --- a/privoxy-generic.init +++ b/privoxy-generic.init @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh # # ******************************************************************** # @@ -36,15 +36,6 @@ # 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.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? @@ -55,37 +46,68 @@ # 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 +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/xpg4/bin:/usr/bin:/sbin:/bin P_NAME=Privoxy # Path to executable. P_DAEMON=privoxy -P_USER=privoxy # Full path to location of Privoxy config file. -P_CONF_FILE=./config +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=`pwd`/${P_USER}.pid -# User that will own the Privoxy process. -P_DAEMON_OWNER="$USER" +# whoever runs this script and by Privoxy itself. +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 [ 0 = `id -u` ]; then + if [ -n "$P_USER" ]; then + id $P_USER 2>/dev/null >/dev/null + if [ $? -eq 0 ]; then + P_USER_SETTINGS="--user $P_USER" + else + echo "User $P_USER doesn't exist, exiting." + exit 1 + fi + else + # The user has sufficient rights, but $P_USER isn't set + echo "Running Privoxy as root is not recommended!" + P_USER_SETTINGS="" + fi +else + # The user has insufficient rights to run Privoxy as $P_USER + # and may not be able to write or delete the PID file. + echo "You aren't root, expect trouble!" + P_USER_SETTINGS="" +fi if [ ! -f $P_CONF_FILE ]; then echo "Can't find $P_CONF_FILE, exiting." exit 1 fi -# If a privoxy user exists, lets use that. /bin/sh does not seem to -# know about $UID. -if [ "$USER" = "root" ] && [ "$P_DAEMON_OWNER" = "$USER" ] && id $P_USER >/dev/null; then - P_DAEMON_OWNER="$P_USER" -fi - case "$1" in start) - test -f $P_PIDFILE && echo "$P_PIDFILE exists, exiting." && exit 1 - $P_DAEMON --pidfile $P_PIDFILE --user $P_DAEMON_OWNER $P_CONF_FILE 2>/dev/null &&\ - echo "Starting $P_NAME, OK." || echo "Starting $P_NAME, 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 $P_USER_SETTINGS $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) @@ -95,7 +117,7 @@ case "$1" in stop) test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1 - kill `cat $P_PIDFILE` &&\ + kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \ echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed." ;;