Added
Link Here
|
1 |
#!/bin/sh |
2 |
### Rozhuk Ivan 2009.12 - 2021 |
3 |
### startup script file for rtorrent |
4 |
### |
5 |
|
6 |
# PROVIDE: rtorrent |
7 |
# REQUIRE: LOGIN |
8 |
# KEYWORD: shutdown |
9 |
|
10 |
. /etc/rc.subr |
11 |
|
12 |
name="rtorrent" |
13 |
rcvar=rtorrent_enable |
14 |
|
15 |
load_rc_config $name |
16 |
|
17 |
: ${rtorrent_enable='NO'} |
18 |
: ${rtorrent_pidfile="/var/run/${name}.pid"} |
19 |
: ${rtorrent_user='www'} |
20 |
: ${rtorrent_group='www'} |
21 |
: ${rtorrent_args=''} |
22 |
: ${rtorrent_bindaddr=''} # Bind listening socket and outgoing connections to this network interface address. |
23 |
: ${rtorrent_bindport=''} # Try to open a listening port in the range a up to and including b |
24 |
: ${rtorrent_download_dir=''} # Set the default download directory. |
25 |
: ${rtorrent_session_dir="/var/db/${name}"} # Session management will be enabled and the torrent files for all open downloads will be stored in this directory. |
26 |
: ${rtorrent_config="%%PREFIX%%/etc/${name}/${name}.conf"} # .rtorrent.rc config file name. |
27 |
: ${rtorrent_rpc_bindaddr=''} # tcp (ip:port) socket for scgi/rpc connect. |
28 |
: ${rtorrent_rpc_bindsocket="/var/run/${name}-rpc.sock"} # Unix domain socket for scgi/rpc connect. |
29 |
: ${rtorrent_rpc_bindsocket_mode='0660'} # Only for unix domain socket. |
30 |
|
31 |
|
32 |
command='/usr/sbin/daemon' |
33 |
procname='%%PREFIX%%/bin/rtorrent' |
34 |
command_args='-n' |
35 |
|
36 |
if [ -n "${rtorrent_bindaddr}" ]; then |
37 |
command_args="${command_args} -b ${rtorrent_bindaddr}" |
38 |
fi |
39 |
if [ -n "${rtorrent_bindport}" ]; then |
40 |
command_args="${command_args} -p ${rtorrent_bindport}" |
41 |
fi |
42 |
if [ -n "${rtorrent_download_dir}" ]; then |
43 |
command_args="${command_args} -d ${rtorrent_download_dir}" |
44 |
fi |
45 |
if [ -n "${rtorrent_session_dir}" ]; then |
46 |
command_args="${command_args} -s ${rtorrent_session_dir}" |
47 |
fi |
48 |
if [ -n "${rtorrent_config}" ]; then |
49 |
command_args="${command_args} -o import=${rtorrent_config}" |
50 |
fi |
51 |
if [ -n "${rtorrent_rpc_bindsocket}" ]; then |
52 |
command_args="${command_args} -o scgi_local=${rtorrent_rpc_bindsocket}" |
53 |
else |
54 |
if [ -n "${rtorrent_rpc_bindaddr}" ]; then |
55 |
command_args="${command_args} -o scgi_local=${rtorrent_rpc_bindaddr}" |
56 |
fi |
57 |
fi |
58 |
command_args="-p ${rtorrent_pidfile} -S -T ${name} ${procname} ${command_args} -o session.path.set=${rtorrent_session_dir} -o system.daemon.set=yes ${rtorrent_args}" |
59 |
|
60 |
|
61 |
pidfile="${rtorrent_pidfile}" |
62 |
required_dirs="${rtorrent_download_dir}" |
63 |
required_files="${command} ${procname}" |
64 |
|
65 |
|
66 |
start_precmd="${name}_clean_cmd" |
67 |
start_postcmd="${name}_start_postcmd" |
68 |
stop_postcmd="${name}_clean_cmd" |
69 |
|
70 |
rtorrent_clean_cmd() |
71 |
{ |
72 |
mkdir -p "${rtorrent_session_dir}" |
73 |
chown -R "${rtorrent_user}:${rtorrent_group}" "${rtorrent_session_dir}" |
74 |
if [ -n "${rtorrent_session_dir}" ]; then |
75 |
rm -f "${rtorrent_session_dir}/rtorrent.lock" |
76 |
fi |
77 |
if [ -e "${rtorrent_rpc_bindsocket}" ]; then |
78 |
rm -f "${rtorrent_rpc_bindsocket}" |
79 |
fi |
80 |
} |
81 |
|
82 |
rtorrent_start_postcmd() |
83 |
{ |
84 |
if [ -S "${rtorrent_rpc_bindsocket}" ]; then |
85 |
sleep 2 |
86 |
chown "${rtorrent_user}:${rtorrent_group} ${rtorrent_rpc_bindsocket}" |
87 |
chmod "${rtorrent_rpc_bindsocket_mode} ${rtorrent_rpc_bindsocket}" |
88 |
fi |
89 |
} |
90 |
|
91 |
run_rc_command "$1" |