-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.d_spdu
92 lines (79 loc) · 2.22 KB
/
rc.d_spdu
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
88
89
90
#! /bin/sh
# $FreeBSD$
#
# spdu startup script
#
# PROVIDE: spdu
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following to /etc/rc.conf[.local] to enable this service
#
# spdu_enable="YES"
# spdu_name="servername"
#
# spdu rc.d script supports multiple targets (a-la rc.d/nginx)
# When targets are specified, the non-target specific parameters become defaults,
# except for spdu_target_name which will default to "target"
#
# This is inspired by and largely copied from
# https://svnweb.freebsd.org/ports/head/www/fcgiwrap/files/fcgiwrap.in?revision=307542&view=co
#
# Example:
#
# spdu_enable="YES"
# spdu_targets="myserver myotherserver"
. /etc/rc.subr
name="spdu"
rcvar=spdu_enable
pidprefix="/var/run/spdu/spdu"
pidfile="${pidprefix}.pid" # May be a different path if targets are in use
target=""
dscript="/usr/local/sbin/${name}"
command="/usr/sbin/daemon"
procname="${command}"
load_rc_config $name
# These are just the defaults, they might get overriden for a specific target.
spdu_enable=${spdu_enable:-"NO"}
spdu_targets=${spdu_targets:-""}
spdu_name=${spdu_name:-""}
spdu_user=${spdu_user:-"root"}
# This handles target specific vars
if [ -n "$2" ]; then
# WARNING: This turns out to be O(2) on the number of targets,
# DO NOT use this rc script for... dozens of targets!
for tag in ${spdu_targets}; do
if [ x"$tag" = x"$2" ]; then
target="$tag"
fi
done
if [ -n "${target}" ]; then
pidfile="${pidprefix}.${target}.pid"
eval spdu_enable="\${spdu_${target}_enable:-${spdu_enable}}"
eval spdu_name="\${spdu_${target}_name:-${target}}"
eval spdu_user="\${spdu_${target}_user:-${spdu_user}}"
else
echo "$0: extra argument ignored because it was not in spdu_targets"
fi
else
if [ -n "${spdu_targets}" -a -n "$1" ]; then
for target in ${spdu_targets}; do
/usr/local/etc/rc.d/spdu $1 ${target}
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${target} (${retcode}) ${failed:-}"
else
success="${target} ${success:-}"
fi
done
# It exits so that non-target rc.d is not started when there are targets.
exit 0
fi
fi
command_args="-S -f -P ${pidfile} ${dscript} ${spdu_name}"
if [ -n "${target}" ]
then
run_rc_command "$1" | /usr/bin/sed -e "s_^_[target=${target}] _"
else
run_rc_command "$1"
fi