blob: 9e7588e14b1833e524dd73b1cb0c4760d7180a15 (
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
|
#!/bin/sh
#
# $FreeBSD$
# Modified by Brian A. Seklecki <bseklecki@collaborativefusion.com>
# <lavalamp@spiritual-machines.org>
# $Id$
#
# sed -e 's/%%PREFIX%%/\/usr\/local/g' < slon.in > slon
# PROVIDE: slon
# REQUIRE: postgresql
# KEYWORD: shutdown
. "/etc/rc.subr"
name="slon"
rcvar=`set_rcvar`
load_rc_config "$name"
_pidprefix="/var/run/${name}"
pidfile="${_pidprefix}.pid" # Used as fall-through in event of no profiles
# From global rc.conf(5); if unset, set them here
[ -z "$slon_enable" ] && slon_enable="NO"
[ -z "$slon_profiles" ] && slon_profiles=""
configfile_path="/usr/local/etc/${name}.conf"
command_args="-f ${configfile_path} -p ${pidfile} &"
required_files="${configfile_path}"
command="/usr/local/bin/slon"
isProfile() {
match=0;
for curMember in $slon_profiles; do
if [ "$curMember" = "$1" ]; then
#echo "DEBUG: Match"
match=1
fi
done
return $match;
}
if [ -n "$2" ]; then
profile="$2" # A profile argument has been given (presumably)
if [ "x${slon_profiles}" != "x" ]; then # This checks that profiles are indeed defined
echo "-- Profile: $profile --"
# Now let's check to make sure that both the profile, the profile's config path variable, config file exists
configfile_default_path="/usr/local/etc/${name}-${profile}.conf"
configfile_override_varname="\$${name}_${profile}_configfile" # Basic string substitution gets variable name
configfile_override_varname_nop="${name}_${profile}_configfile" # Basic string substitution gets variable name
#echo "DEBUG default path: $configfile_default_path"
#echo "DEBUG override variable name: $configfile_override_varname";
#echo "DEBUG override variable name noprefix: $configfile_override_varname_nop";
eval configfile_path=\${$configfile_override_varname_nop:-${configfile_default_path}} # e.g., $configfile_varname="$slon_sex_configfile"
#echo "DEBUG final: $configfile_path";
isProfile $profile
searchForProfile=$?
# testing for true
if [ ! -r "$configfile_path" -o $searchForProfile -lt 1 ]; then
echo "$0: no such profile defined, profile config file defined, or cant read profile config file!";
exit 1;
fi
required_files=${configfile_path}
pidfile_default="${_pidprefix}-${profile}.pid"
eval pidfile=\${${name}_${profile}_pidfile:-${pidfile_default}}
command_args="-f ${configfile_path} -p ${pidfile} &"
#echo "DEBUG argspre: $command_args"
#echo "DEBUG subst: ${name}_${profile}_flags"
#eval echo "DEBUG subst: \$${name}_${profile}_flags"
#eval echo "DEBUG subst2: command_args=\${${name}_${profile}_flags:-${command_args}}"
eval command_args=\${${name}_${profile}_flags:-${command_args}}
#echo "DEBUG args: $command_args"
else
echo "$0: extra profile argument ignored, no profiles defined"
fi
else
# We get to here if $2 is not defined at command line, but we do have profiles
# so apply $1 command to all profiles!
# This block uses recursion to call ourself with each-profile defined as $2
if [ "x${slon_profiles}" != "x" -a "x$1" != "x" ]; then
if [ "x$1" != "xrestart" ]; then
for profile in ${slon_profiles}; do
echo "===> ${name} profile: ${profile}"
/usr/local/etc/rc.d/${name} $1 ${profile}
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${profile} (${retcode}) ${failed:-}"
else
success="${profile} ${success:-}"
fi
done
exit 0
else
restart_precmd=""
fi
fi
# else = no profile argument given
fi
run_rc_command "$1"
|