blob: 7ecef0faf7f90a237d9c4884213cf1c213bd96bc (
plain) (
blame)
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
|
#!/bin/sh
#
# PROVIDE: stalwart
# REQUIRE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name="stalwart"
rcvar="stalwart_enable"
load_rc_config stalwart
: ${stalwart_enable:="NO"}
: ${stalwart_user:="%%USERS%%"}
: ${stalwart_group:="%%GROUPS%%"}
: ${stalwart_config:="%%ETCDIR%%/config.toml"}
: ${stalwart_log:="/var/log/stalwart.log"}
: ${stalwart_path:="/var/db/stalwart"}
pidfile="/var/run/stalwart/server.pid"
procname="%%LOCALBASE%%/bin/stalwart"
start_cmd="stalwart_start"
start_precmd="stalwart_prestart"
stalwart_env="STALWART_PATH=${stalwart_path} RUN_AS_USER=${stalwart_user} RUN_AS_GROUP=${stalwart_group}"
stalwart_prestart() {
if [ ! -f "${stalwart_log}" ]; then
install -o ${stalwart_user} -g ${stalwart_group} -m 0640 /dev/null ${stalwart_log}
fi
if [ ! -d "/var/run/stalwart" ] ; then
install -d -o ${stalwart_user} -g ${stalwart_group} "/var/run/stalwart"
fi
# if empty, RocksDB needs to be initialized
if [ ! -d "${stalwart_path}" ] || [ -z "$(ls -A "${stalwart_path}" 2>/dev/null)" ]; then
stalwart_init
fi
}
stalwart_start()
{
echo -n "Starting Stalwart: "
/usr/sbin/daemon -p ${pidfile} \
-T ${name} \
-o ${stalwart_log} \
${procname} --config ${stalwart_config} \
${stalwart_flags}
echo "done."
}
stalwart_init()
{
mkdir -p ${stalwart_path}
/usr/bin/install -d -o ${stalwart_user} -g ${stalwart_group} -m 0755 ${stalwart_path}
# will tell user of a password it generated in the config we are throwing away
/usr/bin/su -m ${stalwart_user} -c "${procname} -I ${stalwart_path}" 2> /dev/null
# clean up autogenerated etc and logs directories we didn't want
rm -f ${stalwart_path}/etc/config.toml
rmdir ${stalwart_path}/etc
rmdir ${stalwart_path}/logs
}
run_rc_command "$1"
|