Skip to content

Commit 73d4066

Browse files
committed
contrib: FreeBSD rc.d script for tinyice (uses daemon(8))
1 parent 57ba784 commit 73d4066

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

contrib/freebsd/tinyice

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
#
3+
# FreeBSD rc.d script for tinyice.
4+
#
5+
# Drop in /usr/local/etc/rc.d/tinyice, then:
6+
# sysrc tinyice_enable=YES
7+
# sysrc tinyice_user=tinyice
8+
# sysrc tinyice_config=/usr/local/etc/tinyice/tinyice.json
9+
# service tinyice start
10+
#
11+
# Variables (defaults below; override in /etc/rc.conf):
12+
# tinyice_enable — YES to start at boot. Default NO.
13+
# tinyice_user — runtime user. Default tinyice.
14+
# tinyice_group — runtime group. Default tinyice.
15+
# tinyice_bin — binary path. Default /usr/local/bin/tinyice.
16+
# tinyice_config — config file path. Default /usr/local/etc/tinyice/tinyice.json.
17+
# tinyice_workdir — cwd at start. Default /var/db/tinyice.
18+
# tinyice_logfile — combined stdout+stderr. Default /var/log/tinyice.log.
19+
# tinyice_flags — extra args to ${tinyice_bin}.
20+
#
21+
# Privileged ports (80 / 443): on FreeBSD a non-root user can bind low
22+
# ports if `net.inet.ip.portrange.reservedlow=0` is set in sysctl, OR
23+
# you run via daemon(8) and let tinyice drop privs after binding (the
24+
# binary doesn't currently do that), OR run as root and rely on the
25+
# sandbox flags below + ProcessJailing.
26+
# The simplest path: leave tinyice_user blank to run as root, OR set
27+
# the sysctl above. Most tinyice deployments use HTTPS via a frontend
28+
# proxy and bind tinyice on a high port.
29+
30+
# PROVIDE: tinyice
31+
# REQUIRE: NETWORKING
32+
# KEYWORD: shutdown
33+
34+
. /etc/rc.subr
35+
36+
name="tinyice"
37+
rcvar="tinyice_enable"
38+
39+
load_rc_config $name
40+
41+
: ${tinyice_enable:="NO"}
42+
: ${tinyice_user:="tinyice"}
43+
: ${tinyice_group:="tinyice"}
44+
: ${tinyice_bin:="/usr/local/bin/tinyice"}
45+
: ${tinyice_config:="/usr/local/etc/tinyice/tinyice.json"}
46+
: ${tinyice_workdir:="/var/db/tinyice"}
47+
: ${tinyice_logfile:="/var/log/tinyice.log"}
48+
: ${tinyice_flags:=""}
49+
50+
pidfile="/var/run/${name}.pid"
51+
command="/usr/sbin/daemon"
52+
command_args="-r -P ${pidfile} -o ${tinyice_logfile} -t ${name} \
53+
-u ${tinyice_user} \
54+
${tinyice_bin} -config ${tinyice_config} ${tinyice_flags}"
55+
56+
start_precmd="tinyice_precmd"
57+
58+
tinyice_precmd()
59+
{
60+
if [ ! -d "${tinyice_workdir}" ]; then
61+
install -d -o "${tinyice_user}" -g "${tinyice_group}" -m 0750 "${tinyice_workdir}"
62+
fi
63+
if [ ! -f "${tinyice_logfile}" ]; then
64+
install -o "${tinyice_user}" -g "${tinyice_group}" -m 0640 /dev/null "${tinyice_logfile}"
65+
fi
66+
if [ ! -r "${tinyice_config}" ]; then
67+
warn "${tinyice_config} not readable; tinyice will probably exit immediately."
68+
fi
69+
}
70+
71+
run_rc_command "$1"

0 commit comments

Comments
 (0)