#!/sbin/openrc-run conffile="/etc/tor/torrc" pidfile="/run/tor/tor.pid" user="${user:-tor}" graceful_timeout="${GRACEFUL_TIMEOUT:-60}" command="/usr/bin/tor" command_args="-f $conffile" command_background="yes" start_stop_daemon_args=" --user $user --chdir /var/lib/tor --env HOME=/var/lib/tor" # See bug #523552, and https://trac.torproject.org/projects/tor/ticket/5525 # Graceful = wait 30 secs or so until all connections are properly closed. extra_commands="checkconfig" extra_started_commands="graceful gracefulstop reload" description="Anonymizing overlay network for TCP" description_checkconfig="Check if config file is valid." description_reload="Reload the configuration." description_gracefulstop="Gracefully stop." depend() { need net } checkconfig() { # First check that it exists. if [ ! -f "$conffile" ] ; then eerror "You need to setup $conffile first, see $conffile.sample for example" return 1 fi # Now verify whether the configuration is valid. if ! $command --verify-config -f "$conffile" 2>&1 1>/dev/null; then eerror "Tor configuration (${conffile}) not valid" $command --verify-config -f "$conffile" return 1 fi } start_pre() { checkconfig || return 1 checkpath -d -m 0755 -o "$user" "$(dirname "$pidfile")" } gracefulstop() { ebegin "Gracefully stopping Tor, this can take up to $graceful_timeout seconds" start-stop-daemon --stop \ --progress \ --signal INT \ --retry $graceful_timeout \ --pidfile "$pidfile" \ --exec $command -- $command_args eend $? } reload() { start_pre || return 1 ebegin "Reloading Tor configuration" start-stop-daemon --signal HUP --pidfile "$pidfile" eend $? }