Lines 6-18
Link Here
|
6 |
# $Id$ |
6 |
# $Id$ |
7 |
# |
7 |
# |
8 |
|
8 |
|
9 |
# sed -e 's/%%PREFIX%%/\/usr\/local/g' < slon.in > slon |
9 |
# sed -e 's/%%PREFIX%%/\/usr\/local/g' < slon.sh.in > slon |
10 |
|
10 |
|
11 |
# PROVIDE: slon |
11 |
# PROVIDE: slon |
12 |
# REQUIRE: postgresql |
12 |
# REQUIRE: postgresql |
13 |
# KEYWORD: shutdown |
13 |
# KEYWORD: shutdown |
14 |
|
14 |
|
15 |
. "/etc/rc.subr" |
15 |
. /etc/rc.subr |
16 |
|
16 |
|
17 |
name="slon" |
17 |
name="slon" |
18 |
rcvar=`set_rcvar` |
18 |
rcvar=`set_rcvar` |
Lines 20-108
Link Here
|
20 |
load_rc_config "$name" |
20 |
load_rc_config "$name" |
21 |
_pidprefix="/var/run/${name}" |
21 |
_pidprefix="/var/run/${name}" |
22 |
pidfile="${_pidprefix}.pid" # Used as fall-through in event of no profiles |
22 |
pidfile="${_pidprefix}.pid" # Used as fall-through in event of no profiles |
|
|
23 |
procname="%%PREFIX%%/bin/slon" |
23 |
|
24 |
|
24 |
# From global rc.conf(5); if unset, set them here |
25 |
# From global rc.conf(5); if unset, set them here |
25 |
[ -z "$slon_enable" ] && slon_enable="NO" |
26 |
[ -z "$slon_enable" ] && slon_enable="NO" |
26 |
[ -z "$slon_profiles" ] && slon_profiles="" |
27 |
[ -z "$slon_profiles" ] && slon_profiles="" |
27 |
|
28 |
|
28 |
configfile_path="/usr/local/etc/${name}.conf" |
29 |
configfile_path="%%PREFIX%%/etc/${name}.conf" |
29 |
command_args="-f ${configfile_path} -p ${pidfile} &" |
30 |
command_args="-f ${configfile_path}" |
30 |
required_files="${configfile_path}" |
31 |
required_files="${configfile_path}" |
31 |
|
32 |
|
32 |
command="/usr/local/bin/slon" |
33 |
isProfile () { |
|
|
34 |
local profile |
33 |
|
35 |
|
34 |
isProfile() { |
36 |
for profile in $slon_profiles; do |
35 |
match=0; |
37 |
if [ "$profile" = "$1" ]; then |
36 |
for curMember in $slon_profiles; do |
38 |
return 0 |
37 |
if [ "$curMember" = "$1" ]; then |
39 |
fi |
38 |
#echo "DEBUG: Match" |
40 |
done |
39 |
match=1 |
41 |
|
40 |
fi |
42 |
return 1 |
41 |
done |
|
|
42 |
return $match; |
43 |
} |
43 |
} |
44 |
|
44 |
|
|
|
45 |
if [ -n "$2" ]; then |
46 |
if [ "x${slon_profiles}" = "x" ]; then # This checks that profiles are indeed defined |
47 |
echo "$0: extra profile argument ignored, no profiles defined" |
48 |
exit 1 |
49 |
fi |
45 |
|
50 |
|
|
|
51 |
profile="$2" # A profile argument has been given (presumably) |
46 |
|
52 |
|
47 |
if [ -n "$2" ]; then |
53 |
# Now let's check to make sure that both the profile, the profile's |
48 |
profile="$2" # A profile argument has been given (presumably) |
54 |
# config path variable, config file exists |
49 |
if [ "x${slon_profiles}" != "x" ]; then # This checks that profiles are indeed defined |
55 |
|
50 |
echo "-- Profile: $profile --" |
56 |
if ! isProfile $profile; then |
51 |
# Now let's check to make sure that both the profile, the profile's config path variable, config file exists |
57 |
echo "$0: no such profile defined in slon_profiles." |
52 |
configfile_default_path="/usr/local/etc/${name}-${profile}.conf" |
58 |
exit 1 |
53 |
configfile_override_varname="\$${name}_${profile}_configfile" # Basic string substitution gets variable name |
59 |
fi |
54 |
configfile_override_varname_nop="${name}_${profile}_configfile" # Basic string substitution gets variable name |
60 |
|
55 |
#echo "DEBUG default path: $configfile_default_path" |
61 |
configfile_default_path="%%PREFIX%%/etc/${name}-${profile}.conf" |
56 |
#echo "DEBUG override variable name: $configfile_override_varname"; |
62 |
|
57 |
#echo "DEBUG override variable name noprefix: $configfile_override_varname_nop"; |
63 |
# Basic string substitution gets variable name |
58 |
eval configfile_path=\${$configfile_override_varname_nop:-${configfile_default_path}} # e.g., $configfile_varname="$slon_sex_configfile" |
64 |
configfile_varname="${name}_${profile}_configfile" |
59 |
#echo "DEBUG final: $configfile_path"; |
|
|
60 |
isProfile $profile |
61 |
searchForProfile=$? |
62 |
# testing for true |
63 |
if [ ! -r "$configfile_path" -o $searchForProfile -lt 1 ]; then |
64 |
echo "$0: no such profile defined, profile config file defined, or cant read profile config file!"; |
65 |
exit 1; |
66 |
fi |
67 |
required_files=${configfile_path} |
68 |
|
69 |
pidfile_default="${_pidprefix}-${profile}.pid" |
70 |
eval pidfile=\${${name}_${profile}_pidfile:-${pidfile_default}} |
71 |
|
72 |
command_args="-f ${configfile_path} -p ${pidfile} &" |
73 |
#echo "DEBUG argspre: $command_args" |
74 |
#echo "DEBUG subst: ${name}_${profile}_flags" |
75 |
#eval echo "DEBUG subst: \$${name}_${profile}_flags" |
76 |
#eval echo "DEBUG subst2: command_args=\${${name}_${profile}_flags:-${command_args}}" |
77 |
eval command_args=\${${name}_${profile}_flags:-${command_args}} |
78 |
#echo "DEBUG args: $command_args" |
79 |
else |
80 |
echo "$0: extra profile argument ignored, no profiles defined" |
81 |
fi |
82 |
|
83 |
|
65 |
|
|
|
66 |
eval configfile_path=\${$configfile_varname:-${configfile_default_path}} |
67 |
|
68 |
if [ ! -r "$configfile_path" ]; then |
69 |
echo "$0: unable to read configuration file." |
70 |
exit 1 |
71 |
fi |
72 |
|
73 |
required_files="${configfile_path}" |
74 |
|
75 |
pidfile_default="${_pidprefix}-${profile}.pid" |
76 |
eval pidfile=\${${name}_${profile}_pidfile:-${pidfile_default}} |
77 |
|
78 |
command_args="-f ${configfile_path}" |
79 |
eval command_args=\${${name}_${profile}_flags:-${command_args}} |
84 |
else |
80 |
else |
85 |
# We get to here if $2 is not defined at command line, but we do have profiles |
81 |
# We get to here if $2 is not defined at command line, but we do have profiles |
86 |
# so apply $1 command to all profiles! |
82 |
# so apply $1 command to all profiles! |
87 |
# This block uses recursion to call ourself with each-profile defined as $2 |
83 |
# This block uses recursion to call ourself with each-profile defined as $2. |
88 |
if [ "x${slon_profiles}" != "x" -a "x$1" != "x" ]; then |
84 |
|
89 |
if [ "x$1" != "xrestart" ]; then |
85 |
if [ "x${slon_profiles}" != "x" -a "x$1" != "x" ]; then |
90 |
for profile in ${slon_profiles}; do |
86 |
for profile in ${slon_profiles}; do |
91 |
echo "===> ${name} profile: ${profile}" |
87 |
echo "Processing ${name} profile: ${profile}" |
92 |
/usr/local/etc/rc.d/${name} $1 ${profile} |
88 |
%%PREFIX%%/etc/rc.d/${name} $1 ${profile} |
93 |
retcode="$?" |
89 |
done |
94 |
if [ "0${retcode}" -ne 0 ]; then |
90 |
exit 0 |
95 |
failed="${profile} (${retcode}) ${failed:-}" |
91 |
fi |
96 |
else |
|
|
97 |
success="${profile} ${success:-}" |
98 |
fi |
99 |
done |
100 |
exit 0 |
101 |
else |
102 |
restart_precmd="" |
103 |
fi |
104 |
fi |
105 |
# else = no profile argument given |
92 |
# else = no profile argument given |
106 |
fi |
93 |
fi |
107 |
|
94 |
|
|
|
95 |
slon_start () { |
96 |
echo "Starting ${name}." |
97 |
/usr/sbin/daemon -cf -p ${pidfile} %%PREFIX%%/bin/slon ${command_args} |
98 |
} |
99 |
|
100 |
start_cmd=slon_start |
101 |
|
108 |
run_rc_command "$1" |
102 |
run_rc_command "$1" |