blob: feb08b644011330e349eb34adf5a32be20379c8c (
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
|
#!/bin/sh
# PROVIDE: samplicator
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line(s) to /etc/rc.conf to enable samplicator:
#
# samplicator_enable="YES"
# # optional
# samplicator_flags="-S -p 2055 -c %%PREFIX%%/etc/samplicator.conf"
# samplicator_runas="nobody"
#
# The default is to run samplicator as nobody, which will prevent you from
# using the -S flag (maintain (spoof) source addresses).
# If you want to maintain (spoof) source addresses, you will need to run as
# root.
# This can be accomplished by adding samplicator_runas="root" to /etc/rc.conf
. /etc/rc.subr
name=samplicator
rcvar=samplicator_enable
load_rc_config $name
# Set defaults
: ${samplicator_enable:=NO}
: ${samplicator_flags="-p 2055 -c %%PREFIX%%/etc/samplicator.conf"}
: ${samplicator_runas:=nobody}
pidfile=/var/run/samplicator.pid
procname="%%PREFIX%%/bin/samplicate"
command=/usr/sbin/daemon
command_args=" -cf -p ${pidfile} -u ${samplicator_runas} ${procname} ${samplicator_flags}"
required_files=%%PREFIX%%/etc/samplicator.conf
start_precmd=samplicator_precmd
stop_postcmd="[ -f ${pidfile} ] && rm ${pidfile}"
samplicator_precmd()
{
# bypass rc_flags as we use samplicator_flags directly via daemon(8)
rc_flags=""
# create empty pidfile with correct permissions
install -o ${samplicator_runas} /dev/null ${pidfile}
# since we are using daemon(8) to drop privs, we cannot let samplicator fork
echo "${samplicator_flags}" | egrep -q "(^\-f| \-f)"
if [ $? -eq 0 ]; then
echo "Please remove parameter -f from samplicator_flags"
echo
return 1
fi
# root is required for -S, do a pre-launch sanity check
echo "${samplicator_flags}" | egrep -q "(^\-S| \-S)"
if [ $? -eq 0 ] && [ $(id -u ${samplicator_runas}) -ne 0 ]; then
echo "-S requires that samplicator_runas be set to root."
echo
return 1
fi
}
run_rc_command "$1"
|