Added
Link Here
|
1 |
#!/bin/sh |
2 |
|
3 |
# PROVIDE: sopel |
4 |
# REQUIRE: LOGIN |
5 |
# KEYWORD: shutdown |
6 |
# |
7 |
# Configuration settings for sopel in /etc/rc.conf |
8 |
# |
9 |
# sopel_enable (bool): Enable sopel. (default=NO) |
10 |
# sopel_piddir (str): Directory in which to put the process ID file. (default=/var/run/sopel) |
11 |
# sopel_confdir (str): Configuration directory. (default=%%ETCDIR%%) |
12 |
# sopel_flags (str): Flags used for sopel. (default=--config-dir "${sopel_confdir}") |
13 |
# sopel_script (str): Path to sopel application. (default=%%PREFIX%%/bin/sopel) |
14 |
# sopel_user (str): User to run sopel as. (default=sopel) |
15 |
# sopel_profiles (str): List of profiles for running multiple sopel instances. |
16 |
# (default=default) |
17 |
# sopel_prefix (str): Each profile or configuration file must begin with thix prefix |
18 |
# followed by the profile name, followed by the extension .cfg, |
19 |
# such as sopel-default.cfg, sopel-libera.chat.cfg, etc. |
20 |
# (default=sopel-) |
21 |
# sopel_output (str): Send stdout and stderr to a file. If you set the logdir parameter in |
22 |
# the sopel file configuration, your best option is to send the output |
23 |
# to /dev/null. But this can be changed for debugging. |
24 |
# (default=/dev/null) |
25 |
|
26 |
. /etc/rc.subr |
27 |
|
28 |
name=sopel |
29 |
rcvar=sopel_enable |
30 |
desc="Simple, easy-to-use, open-source IRC utility bot, written in Python" |
31 |
start_precmd=sopel_checkprofile |
32 |
stop_precmd=sopel_checkprofile |
33 |
start_cmd=sopel_start |
34 |
stop_cmd=sopel_stop |
35 |
restart_cmd=sopel_restart |
36 |
status_cmd=sopel_status |
37 |
configure_cmd=sopel_configure |
38 |
extra_commands="configure status" |
39 |
command_interpreter="%%PYTHON_CMD%%" |
40 |
|
41 |
load_rc_config $name |
42 |
|
43 |
: ${sopel_enable:=NO} |
44 |
: ${sopel_piddir:=/var/run/sopel} |
45 |
: ${sopel_confdir:=%%ETCDIR%%} |
46 |
: ${sopel_flags=--config-dir "${sopel_confdir}"} |
47 |
: ${sopel_script:=%%PREFIX%%/bin/sopel} |
48 |
: ${sopel_user:=sopel} |
49 |
: ${sopel_profiles:=default} |
50 |
: ${sopel_prefix:=sopel-} |
51 |
: ${sopel_output:=/dev/null} |
52 |
|
53 |
sopel_checkprofile() |
54 |
{ |
55 |
if ! [ -f "${sopel_confdir}/${sopel_prefix}${profile}.cfg" ]; then |
56 |
echo "Sopel profile '${profile}' does not exist." |
57 |
return 1 |
58 |
fi |
59 |
|
60 |
return 0 |
61 |
} |
62 |
|
63 |
sopel_start() |
64 |
{ |
65 |
local profile |
66 |
|
67 |
profile="$1"; shift |
68 |
|
69 |
echo "Starting sopel profile '${profile}'." && sleep 1 |
70 |
daemon \ |
71 |
-o "${sopel_output}" \ |
72 |
-t "${desc}" \ |
73 |
-u "${sopel_user}" \ |
74 |
${command_interpreter} \ |
75 |
${sopel_script} start ${sopel_flags} \ |
76 |
-c "${sopel_prefix}${profile}" $@ |
77 |
} |
78 |
|
79 |
sopel_stop() |
80 |
{ |
81 |
local pid pidfile profile |
82 |
|
83 |
profile="$1"; shift |
84 |
|
85 |
pidfile="${sopel_piddir}/sopel-${sopel_prefix}${profile}.pid" |
86 |
if ! [ -f "${pidfile}" ]; then |
87 |
echo "sopel profile '${profile}' not running? (check ${sopel_piddir}/sopel-${sopel_prefix}${profile}.pid)." |
88 |
return 1 |
89 |
fi |
90 |
|
91 |
pid=`cat ${pidfile}` |
92 |
|
93 |
echo "Stopping sopel profile '${profile}'." |
94 |
daemon \ |
95 |
-o "${sopel_output}" \ |
96 |
${command_interpreter} \ |
97 |
${sopel_script} stop ${sopel_flags} \ |
98 |
-c "${sopel_prefix}${profile}" $@ |
99 |
|
100 |
wait_for_pids $pid |
101 |
} |
102 |
|
103 |
sopel_restart() |
104 |
{ |
105 |
local profile |
106 |
|
107 |
profile="$1"; shift |
108 |
|
109 |
run_rc_command stop "${profile}" $@ |
110 |
run_rc_command start "${profile}" $@ |
111 |
} |
112 |
|
113 |
sopel_status() |
114 |
{ |
115 |
local profile pid |
116 |
|
117 |
profile="$1"; shift |
118 |
|
119 |
pid=`check_pidfile \ |
120 |
"${sopel_piddir}/sopel-${sopel_prefix}${profile}.pid" \ |
121 |
"${sopel_script}" \ |
122 |
"${command_interpreter}"` |
123 |
|
124 |
if [ -n "${pid}" ]; then |
125 |
echo "Sopel profile '${profile}' is running as pid ${pid}." |
126 |
else |
127 |
echo "Sopel profile '${profile}' is not running." |
128 |
fi |
129 |
} |
130 |
|
131 |
sopel_configure() |
132 |
{ |
133 |
local profile |
134 |
|
135 |
profile="$1"; shift |
136 |
|
137 |
echo "Configuring profile '${profile}'..." |
138 |
|
139 |
${command_interpreter} \ |
140 |
${sopel_script} configure ${sopel_flags} \ |
141 |
-c "${sopel_confdir}/${sopel_prefix}${profile}" $@ |
142 |
} |
143 |
|
144 |
cmd="$1"; shift |
145 |
for profile in ${sopel_profiles}; do |
146 |
run_rc_command "${cmd}" "${profile}" $@ |
147 |
done |