blob: 653bf3f584957331539c28db00f14937b4cf0f0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#!/bin/sh
# PROVIDE: hommabot
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="hommabot"
rcvar="${name}_enable"
load_rc_config "${name}"
: ${hommabot_enable:="NO"}
: ${hommabot_token_file:="%%PREFIX%%/etc/hommabot.token"}
: ${hommabot_data_dir:="/var/db/hommabot"}
: ${hommabot_tz:="Europe/Helsinki"}
: ${hommabot_log_file:="/var/log/hommabot.log"}
pidfile="/var/run/${name}.pid"
procname="/usr/sbin/daemon"
start_precmd="${name}_prestart"
start_cmd="${name}_start"
hommabot_prestart()
{
if [ ! -r "${hommabot_token_file}" ]; then
echo "${name}: token file ${hommabot_token_file} does not exist or is not readable"
return 1
fi
if [ ! -s "${hommabot_token_file}" ]; then
echo "${name}: token file ${hommabot_token_file} is empty"
return 1
fi
install -d -m 0700 "${hommabot_data_dir}" || {
echo "${name}: cannot create ${hommabot_data_dir}"
return 1
}
if [ ! -e "${hommabot_log_file}" ]; then
install -m 0600 /dev/null "${hommabot_log_file}" || {
echo "${name}: cannot create ${hommabot_log_file}"
return 1
}
else
chmod 0600 "${hommabot_log_file}" || {
echo "${name}: cannot set permissions on ${hommabot_log_file}"
return 1
}
fi
}
hommabot_start()
{
local bot_token
bot_token=$(cat "${hommabot_token_file}") || {
echo "${name}: cannot read ${hommabot_token_file}"
return 1
}
cd "%%PREFIX%%/libexec/hommabot" || {
echo "${name}: cannot change to %%PREFIX%%/libexec/hommabot"
return 1
}
echo "Starting ${name}."
exec /usr/sbin/daemon \
-f \
-H \
-P "${pidfile}" \
-o "${hommabot_log_file}" \
/usr/bin/env \
PATH="%%PREFIX%%/bin:/usr/bin:/bin" \
TELEGRAM_BOT_TOKEN="${bot_token}" \
SQLITE_PATH="${hommabot_data_dir}/db.sqlite3" \
TZ="${hommabot_tz}" \
"%%PREFIX%%/bin/node" \
"%%PREFIX%%/libexec/hommabot/node_modules/tsx/dist/cli.mjs" \
"%%PREFIX%%/libexec/hommabot/src/bot.ts"
}
run_rc_command "$1"
|