Bump tor to 0.4.2.7
[librecmc/librecmc.git] / package / network / services / tor / files / tor.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
3
4 START=50
5 STOP=50
6
7 USE_PROCD=1
8
9 TORRC_GEN="/tmp/torrc"
10
11 handle_conf_file() {
12         local conf_path="$1"
13         if [ -f "$conf_path" ] || [ -d "$conf_path" ]; then
14                 echo "%include $conf_path"
15         fi
16 }
17
18 generate_conf() {
19         local default_conf generated_conf
20
21         config_load tor
22         config_get default_conf conf default "/etc/tor/torrc"
23         config_get generated_conf conf generated "/tmp/torrc"
24         TORRC_GEN="$generated_conf"
25
26         {
27         echo "## This file was automatically generated please do not edit here !"
28         config_list_foreach "conf" head_include handle_conf_file
29         echo "%include $default_conf"
30         config_list_foreach "conf" tail_include handle_conf_file
31         } > "$TORRC_GEN"
32 }
33
34 reload_service() {
35         procd_send_signal /usr/sbin/tor
36 }
37
38 start_service() {
39         mkdir -m 0700 -p /var/lib/tor
40         chown -R tor:tor /var/lib/tor
41
42         mkdir -m 0755 -p /var/log/tor
43         chown -R tor:tor /var/log/tor
44
45         generate_conf
46
47         procd_open_instance
48         procd_set_param command /usr/sbin/tor --runasdaemon 0
49         procd_append_param command -f "$TORRC_GEN"
50         procd_set_param respawn
51         procd_close_instance
52 }