#!/bin/sh # # Name: /etc/init.d/tor (shell script for SystemV style INIT) # This script has the Tor service directory hard-coded as /var/tor. # ### BEGIN INIT INFO # Provides: tor # Required-Start: $local_fs $network $syslog # Required-Stop: $local_fs $syslog # Should-Start: $syslog # Should-Stop: $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start up Tor locally # Description: start a local Tor server if only for SOCKS # ### END INIT INFO # source function library #. /etc/rc.d/init.d/functions # conditionally augment command search path if [ -d /usr/opt/tor/bin ] ; then PATH=/usr/opt/tor/bin:$PATH ; fi export PATH # conditionally augment library search path if [ -d /usr/opt/apache/lib ] ; then if [ -z "$LD_LIBRARY_PATH" ] ; then LD_LIBRARY_PATH=/usr/opt/apache/lib else LD_LIBRARY_PATH=/usr/opt/apache/lib:$LD_LIBRARY_PATH fi export LD_LIBRARY_PATH fi # set defaults and/or collect findings TORID=tor TORD=tor if [ -x /usr/opt/tor/bin/tor ] ; then TORD=/usr/opt/tor/bin/tor ; fi SSHD=sshd if [ -x /usr/sbin/sshd ] ; then SSHD=/usr/sbin/sshd ; fi HTTPD=httpd if [ -x /usr/sbin/httpd ] ; then HTTPD=/usr/sbin/httpd ; fi if [ -x /opt/apache/bin/httpd ] ; then HTTPD=/opt/apache/bin/httpd ; fi if [ -x /usr/opt/apache/bin/httpd ] ; then HTTPD=/usr/opt/apache/bin/httpd ; fi NGINX=nginx # pull in sysconfig settings [ -f /etc/sysconfig/tor ] && . /etc/sysconfig/tor RETVAL=0 #prog=tor #lockfile=/var/lock/subsys/$prog # Some functions to make the below more readable #runlevel=$(set -- $(runlevel); eval "echo \$$#" ) cd /var/tor case "$1" in start) su - $TORID -c " $TORD -f /etc/tor/torrc & " \ 0< /dev/null 1> /var/log/tor 2>&1 if [ -r /etc/tor/httpd.conf -a -x "$HTTPD" ] ; then $HTTPD -f /etc/tor/httpd.conf -d /etc/tor/httpd elif [ -r /etc/tor/nginx.conf -a -x "$NGINX" ] ; then $NGINX -c /etc/tor/nginx.conf -p /etc/tor/nginx fi if [ -r /etc/tor/sshd_config -a -x "$SSHD" ] ; then $SSHD -f /etc/tor/sshd_config ; fi ;; stop) if [ -s /var/tor/tor.pid ] ; then cat /var/tor/tor.pid | xargs kill ; fi if [ -s /var/tor/sshd.pid ] ; then cat /var/tor/sshd.pid | xargs kill ; fi if [ -s /var/tor/httpd.pid ] ; then cat /var/tor/httpd.pid | xargs kill ; fi if [ -s /var/tor/nginx.pid ] ; then cat /var/tor/nginx.pid | xargs kill ; fi ;; restart) $0 stop ; sleep 3 $0 start : ;; reload) : ;; force-reload) : ;; condrestart|try-restart) : ;; status) : ;; *) echo $"Usage: $0 {start|stop|restart}" RETVAL=2 ;; esac exit $RETVAL