blob: d18e4326e3f0a09beaf92bd41631282a4b067865 (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#!/bin/sh
# $FreeBSD$
#
# PROVIDE: netdisco
# REQUIRE: DAEMON LOGIN
# AFTER: postgresql
# KEYWORD: shutdown
. /etc/rc.subr
name="netdisco"
rcvar="netdisco_enable"
start_precmd="netdisco_start_precmd"
start_cmd="netdisco_cmd"
stop_cmd="netdisco_cmd"
status_cmd="netdisco_cmd"
reload_cmd="netdisco_reload_cmd"
rcvar_cmd="netdisco_rcvar_cmd"
extra_commands="reload status"
: ${netdisco_home="/var/run/netdisco"}
: ${netdisco_user="netdisco"}
: ${netdisco_group="netdisco"}
netdisco_daemons="web daemon"
netdisco_start_precmd() {
# /var/run and /var/log
if [ ! -d /var/run/netdisco ]; then
mkdir /var/run/netdisco
chown -R netdisco:netdisco /var/run/netdisco
fi
if [ ! -d /var/log/netdisco ]; then
mkdir /var/log/netdisco
chown netdisco:netdisco /var/log/netdisco
fi
if [ ! -d /usr/local/etc/netdisco/logs ]; then
ln -s /var/log/netdisco /usr/local/etc/netdisco/logs
fi
# populate /var/run/netdisco
for dir in environments perl5 netdisco-mibs; do
test -d /var/run/netdisco/$dir || ln -fs /usr/local/etc/netdisco/$dir /var/run/netdisco/$dir
done
test -d /var/run/netdisco/logs || ln -s /var/log/netdisco /var/run/netdisco/logs
}
netdisco_cmd() {
local name rcvar rcvars v command pidfile netdisco_daemons result force_run interpreter
# Prevent recursive calling
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
# Ignore rcvar and run command
if [ -n "${_rc_prefix}" -a "${_rc_prefix}" = "one" ] || [ -n "${rc_force}" ] || [ -n "${rc_fast}" ]; then
force_run=yes
fi
# Assume success
result=0
# Apply to all daemons
for n in ${netdisco_daemons}; do
name="netdisco_$n"
rcvars=''; v=''
name=${name}
rcvar=${name}_enable
command="/usr/local/bin/netdisco-${n}"
command_args=${rc_arg}
pidfile="/var/run/netdisco/netdisco-${n}.pid"
[ "$n" = "web" ] && command_interpreter="perl" || command_interpreter=""
# Daemon should be enabled and running
if ( [ -n "${rcvar}" ] && checkyesno "${rcvar}" ) || [ -n "$force_run" ]; then
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
# If any of the commands failed, take it as a global result
result=$((${result} || $?))
fi
done
return ${result}
}
netdisco_rcvar_cmd() {
local name rcvar
rcvar=${name}_enable
# Prevent recursive calling
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
# Check master variable
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
# Check dependent variables
for n in ${netdisco_daemons}; do
name=netdisco_${n}
# XXX
rcvars=''; v=''
rcvar=${name}_enable
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
done
}
netdisco_config_init() {
local name
load_rc_config "${name}"
for n in ${netdisco_daemons}; do
load_rc_config "netdisco_${n}"
done
# Defaults
netdisco_enable=${netdisco_enable:=NO}
if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
netdisco_web_enable=${netdisco_enable}
netdisco_daemon_enable=${netdisco_enable}
fi
netdisco_web_enable=${netdisco_web_enable:-NO}
netdisco_web_pidfile=${netdisco_web_pidfile:-"/var/run/netdisco/netdisco-web.pid"}
netdisco_daemon_enable=${netdisco_daemon_enable:-NO}
netdisco_web_user=${netdisco_user}
netdisco_daemon_user=${netdisco_user}
netdisco_web_group=${netdisco_group}
netdisco_daemon_group=${netdisco_group}
export NETDISCO_HOME=/var/run/netdisco
}
# load config
netdisco_config_init
run_rc_command "$1"
|