privoxy-generic.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. ###########################################################################
  3. #
  4. # File : $Source: /cvsroot/ijbswa/current/privoxy-generic.init,v $
  5. #
  6. # Purpose : This script takes care of starting and stopping privoxy.
  7. # It is supposed to work cross-platform and thus doesn't
  8. # do too much. When packaging Privoxy it's recommended to
  9. # write a platform-specific start script instead of using
  10. # this one.
  11. #
  12. # Copyright : Written by and Copyright (C) 2001,2002 the
  13. # Privoxy team. https://www.privoxy.org/
  14. #
  15. # This program is free software; you can redistribute it
  16. # and/or modify it under the terms of the GNU General
  17. # Public License as published by the Free Software
  18. # Foundation; either version 2 of the License, or (at
  19. # your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will
  22. # be useful, but WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A
  24. # PARTICULAR PURPOSE. See the GNU General Public
  25. # License for more details.
  26. #
  27. # The GNU General Public License should be included with
  28. # this file. If not, you can view it at
  29. # http://www.gnu.org/copyleft/gpl.html
  30. # or write to the Free Software Foundation, Inc., 59
  31. # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32. #
  33. ###########################################################################
  34. ### BEGIN INIT INFO
  35. # Provides: privoxy
  36. # Required-Start:
  37. # Required-Stop:
  38. # Default-Start: 2 3 4 5
  39. # Default-Stop: 0 1 6
  40. # Short-Description: Start privoxy at boot time
  41. # Description: Start and stop the privacy-enhancing HTTP proxy privoxy.
  42. ### END INIT INFO
  43. # NOTE: This script may require editing to ensure proper location of
  44. # config file, and the privoxy executable. Care should be taken to ensure
  45. # logfile is writable by $P_USER (logfile is defined in config), and that
  46. # there is suitable write access for $P_PIDFILE.
  47. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/xpg4/bin:/usr/bin:/sbin:/bin
  48. P_NAME=Privoxy
  49. # Path to executable.
  50. P_DAEMON=privoxy
  51. # Full path to location of Privoxy config file.
  52. P_CONF_FILE=/usr/local/etc/privoxy/config
  53. # Full path to PID file location. Location must be writable by
  54. # whoever runs this script and by Privoxy itself.
  55. P_PIDFILE=/var/run/privoxy.pid
  56. # If uncommented, this script will try to run as USER=privoxy, which
  57. # may require special handling of config, *.action, trust, logfile,
  58. # jarfile, and pidfile.
  59. P_USER=privoxy
  60. # If a privoxy user is specified, lets try that. /bin/sh does not seem to
  61. # know about $UID.
  62. if [ 0 = `id -u` ]; then
  63. if [ -n "$P_USER" ]; then
  64. id $P_USER 2>/dev/null >/dev/null
  65. if [ $? -eq 0 ]; then
  66. P_USER_SETTINGS="--user $P_USER"
  67. else
  68. echo "User $P_USER doesn't exist, exiting."
  69. exit 1
  70. fi
  71. else
  72. # The user has sufficient rights, but $P_USER isn't set
  73. echo "Running Privoxy as root is not recommended!"
  74. P_USER_SETTINGS=""
  75. fi
  76. else
  77. # The user has insufficient rights to run Privoxy as $P_USER
  78. # and may not be able to write or delete the PID file.
  79. echo "You aren't root, expect trouble!"
  80. P_USER_SETTINGS=""
  81. fi
  82. if [ ! -f $P_CONF_FILE ]; then
  83. echo "Can't find $P_CONF_FILE, exiting."
  84. exit 1
  85. fi
  86. case "$1" in
  87. start)
  88. if [ -f $P_PIDFILE ]; then
  89. if kill -0 `cat $P_PIDFILE`; then
  90. echo "Error: $P_NAME is already running, exiting."
  91. exit 1
  92. else
  93. rm -f $P_PIDFILE
  94. fi
  95. fi
  96. $P_DAEMON --pidfile $P_PIDFILE $P_USER_SETTINGS $P_CONF_FILE 2>/dev/null
  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. restart)
  105. $0 stop
  106. $0 start
  107. ;;
  108. stop)
  109. test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
  110. kill `cat $P_PIDFILE` && rm -f $P_PIDFILE && \
  111. echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
  112. ;;
  113. *)
  114. echo "Usage: $0 {start|stop|restart}"
  115. exit 1
  116. ;;
  117. esac
  118. exit 0