Lines 11-35
Link Here
|
11 |
# they are command line options. |
11 |
# they are command line options. |
12 |
# |
12 |
# |
13 |
# tor_enable (bool): Set it to "YES" to enable tor. Default: NO |
13 |
# tor_enable (bool): Set it to "YES" to enable tor. Default: NO |
|
|
14 |
# tor_instances (str): List of instances. Default: "" |
14 |
# tor_conf (str): Points to your torrc file. |
15 |
# tor_conf (str): Points to your torrc file. |
15 |
# Default: %%PREFIX%%/etc/tor/torrc |
16 |
# Default: %%PREFIX%%/etc/tor/torrc |
16 |
# tor_user (str): Tor daemon user. Default: _tor |
17 |
# tor_user (str): Tor daemon user. Default: %%USER%% |
|
|
18 |
# tor_group (str): Tor group. Default: %%GROUP%% |
19 |
# tor_pidfile (str): Tor pid file. Default: /var/run/tor/tor.pid |
17 |
# tor_datadir (str): Tor datadir. Default: /var/db/tor |
20 |
# tor_datadir (str): Tor datadir. Default: /var/db/tor |
|
|
21 |
# tor_disable_default_instance (str): Doesn't run the default instance. |
22 |
# Only valid when tor_instances is used. |
23 |
# Default: NO |
18 |
# |
24 |
# |
|
|
25 |
# The instance definition that tor_instances expects: |
26 |
# inst_name{:inst_conf:inst_user:inst_group:inst_pidfile:inst_data_dir} |
27 |
# |
19 |
|
28 |
|
20 |
. /etc/rc.subr |
29 |
. /etc/rc.subr |
21 |
|
30 |
|
22 |
name="tor" |
31 |
name="tor" |
23 |
rcvar=tor_enable |
32 |
rcvar=tor_enable |
|
|
33 |
exit_code=0 |
24 |
|
34 |
|
25 |
load_rc_config ${name} |
35 |
load_rc_config ${name} |
26 |
|
36 |
|
27 |
: ${tor_enable="NO"} |
37 |
: ${tor_enable="NO"} |
|
|
38 |
: ${tor_instances=""} |
28 |
: ${tor_conf="%%PREFIX%%/etc/tor/torrc"} |
39 |
: ${tor_conf="%%PREFIX%%/etc/tor/torrc"} |
29 |
: ${tor_user="_tor"} |
40 |
: ${tor_user="%%USER%%"} |
|
|
41 |
: ${tor_group="%%GROUP%%"} |
30 |
: ${tor_pidfile="/var/run/tor/tor.pid"} |
42 |
: ${tor_pidfile="/var/run/tor/tor.pid"} |
31 |
: ${tor_datadir="/var/db/tor"} |
43 |
: ${tor_datadir="/var/db/tor"} |
|
|
44 |
: ${tor_disable_default_instance="NO"} |
32 |
|
45 |
|
|
|
46 |
instance=${slave_instance} |
47 |
if [ -n "${instance}" ]; then |
48 |
inst_def=${instance} |
49 |
inst_name=${inst_def%%:*} |
50 |
[ "${inst_name}" != "main" ] || err 1 "${name} instance can't be named 'main'" |
51 |
inst_def=${inst_def#$inst_name} |
52 |
if [ -n "$inst_def" ]; then |
53 |
# extended instance: parameters are set explicitly |
54 |
inst_def=${inst_def#:} |
55 |
tor_conf=${inst_def%%:*} |
56 |
inst_def=${inst_def#$tor_conf:} |
57 |
tor_user=${inst_def%%:*} |
58 |
inst_def=${inst_def#$tor_user:} |
59 |
tor_group=${inst_def%%:*} |
60 |
inst_def=${inst_def#$tor_group:} |
61 |
tor_pidfile=${inst_def%%:*} |
62 |
tor_datadir=${inst_def#$tor_pidfile:} |
63 |
if [ -z "${tor_conf}" -o -z "${tor_user}" -o -z "${tor_group}" -o -z "${tor_pidfile}" -o -z "${tor_datadir}" ]; then |
64 |
warn "invalid tor instance ${inst_name} settings: ${instance}" |
65 |
exit 1 |
66 |
fi |
67 |
else |
68 |
# regular instance: default parameters are used |
69 |
tor_conf=${tor_conf}@${inst_name} |
70 |
tor_pidfile=${tor_pidfile}@${inst_name} |
71 |
tor_datadir=${tor_datadir}/instance@${inst_name} |
72 |
fi |
73 |
if ! [ -r ${tor_conf} ]; then |
74 |
warn "tor instance ${inst_name} config file ${tor_conf} doesn't exist or isn't readable" |
75 |
warn "you can copy the sample config %%PREFIX%%/etc/tor/torrc.sample and modify it" |
76 |
exit 1 |
77 |
fi |
78 |
if ! [ -d ${tor_datadir} ]; then |
79 |
mkdir -p ${tor_datadir} && |
80 |
chown ${tor_user}:${tor_group} ${tor_datadir} && |
81 |
chmod 0700 ${tor_datadir} && |
82 |
echo "${name}: created the instance data directory ${tor_datadir}" |
83 |
fi |
84 |
fi |
85 |
|
86 |
if [ -z "${instance}" -a -n "${tor_instances}" ]; then |
87 |
inst_only="$2" |
88 |
inst_done=0 |
89 |
for i in ${tor_instances}; do |
90 |
inst_name=${i%%:*} |
91 |
if [ -z "${inst_only}" -o "${inst_name}" = "${inst_only}" ]; then |
92 |
echo -n "${name} instance ${inst_name}: " |
93 |
if ! slave_instance=${i} %%PREFIX%%/etc/rc.d/tor "$1"; then |
94 |
exit_code=1 |
95 |
fi |
96 |
inst_done=$((inst_done+1)) |
97 |
fi |
98 |
done |
99 |
if [ -z "${inst_only}" -o "${inst_only}" = "main" ]; then |
100 |
checkyesno tor_disable_default_instance && return $exit_code |
101 |
echo -n "${name} main instance: " |
102 |
elif [ -n "${inst_only}" ]; then |
103 |
[ $inst_done -gt 0 ] || err 1 "${name} instance '$inst_only' isn't defined" |
104 |
return $exit_code |
105 |
fi |
106 |
fi |
107 |
|
33 |
required_files=${tor_conf} |
108 |
required_files=${tor_conf} |
34 |
required_dirs=${tor_datadir} |
109 |
required_dirs=${tor_datadir} |
35 |
pidfile=${tor_pidfile} |
110 |
pidfile=${tor_pidfile} |
Lines 37-41
Link Here
|
37 |
command_args="-f ${tor_conf} --PidFile ${tor_pidfile} --RunAsDaemon 1 --DataDirectory ${tor_datadir}" |
112 |
command_args="-f ${tor_conf} --PidFile ${tor_pidfile} --RunAsDaemon 1 --DataDirectory ${tor_datadir}" |
38 |
extra_commands="reload" |
113 |
extra_commands="reload" |
39 |
|
114 |
|
40 |
run_rc_command "$1" |
115 |
if ! run_rc_command "$1"; then |
|
|
116 |
exit_code=1 |
117 |
fi |
41 |
|
118 |
|
|
|
119 |
return $exit_code |