blob: 7e55e62960d2b305aa36d81d3af1847eacdc97fb (
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#!/bin/sh
# PROVIDE: rubyrep
# REQUIRE: NETWORKING SERVERS
# KEYWORD: shutdown
# Add the following line to /etc/rc.conf to enable `rubyrep':
#rubyrep_enable="YES"
# and be sure to configure (at least)
# %%PREFIX%%/etc/rubyrep/rubyrep.conf
#
# To replicate more than one database, change
#rubyrep_multi="NO"
# to "YES". A rubyrep process will be started for each file with
# .conf suffix in $rubyrep_config_dir.
#
# Additional options:
#
#rubyrep_stdout_log="/var/log/rubyrep.fifo"
#rubyrep_stderr_log="/var/log/rubyrep_err.fifo"
#rubyrep_fifo_logs="YES"
# Specify log files for stdout and stderr. Defaults to using fifos;
# actual log file will have the extension .log. Additional PID files
# will be created for each of the processes used to tap the fifos;
# these can be used in newsyslog.conf(5) to automate log rotation.
#
#rubyrep_config="%%PREFIX%%/etc/rubyrep.conf"
# Specify full path to default rubyrep configuration file.
# NOTE: Ignored if $rubyrep_multi is set to "YES"!
#
#rubyrep_config_dir="%%PREFIX%%/etc/rubyrep"
# Specify directory containing config files for rubyrep. Used
# by $rubyrep_multi, ignored if $rubyrep_multi="NO" (the default).
#
#rubyrep_command="replicate"
# Specify the command to pass to rubyrep. Usually you'll want to
# replicate (the default), but it is also possible to specify "proxy",
# "scan" or "sync". Note: This option applies to all databases if
# $rubyrep_multi="YES"!
#
#rubyrep_command_flags=""
# Specify options to pass to the $rubyrep_command above. For other
# operating modes than "replicate" this may be necessary, especially
# if you want useful log output! Run
# %%prefix%%/bin/rubyrep <command> --help
# for further information.
rubyrep_enable="${rubyrep_enable:-"NO"}"
rubyrep_multi="${rubyrep_multi:-"NO"}"
rubyrep_command="${rubyrep_command:-"replicate"}"
rubyrep_command_flags="${rubyrep_command_flags:-""}"
rubyrep_config="${rubyrep_config:-"%%PREFIX%%/etc/rubyrep.conf"}"
rubyrep_config_dir="${rubyrep_config_dir:-"%%PREFIX%%/etc/rubyrep"}"
rubyrep_user="${rubyrep_user:-"daemon"}"
rubyrep_stdout_log="${rubyrep_stdout_log:-"/var/log/rubyrep.fifo"}"
rubyrep_stderr_log="${rubyrep_stderr_log:-"/var/log/rubyrep_err.fifo"}"
rubyrep_fifo_logs="YES"
. /etc/rc.subr
checkfifo() {
# Check and create if necessary fifo special files for logging
for f in $stdout_log $stderr_log ; do
flog_fifo=$f
if [ ! -p "$flog_fifo" ] ; then
mkfifo $flog_fifo ; chown ${rubyrep_user} $flog_fifo
fi
done
}
pid_touch () {
touch $pidfile
chown $rubyrep_user $pidfile
}
rubyrep_prestart() {
pid_touch
if [ "$rubyrep_fifo_logs"="YES" ] ; then
umask 027
checkfifo
for f in $stdout_log $stderr_log ; do
flog_fifo=$f
flog_args=" -t "
if [ "$cfgname" ] ; then
local out_log="`dirname $f`/`basename -s .fifo.$cfgname $flog_fifo`.$cfgname.log"
local out_pid="/var/run/`basename -s .fifo.$cfgname $flog_fifo`.$cfgname.flog.pid"
else
local out_log="`dirname $f`/`basename -s .fifo $flog_fifo`.log"
local out_pid="/var/run/`basename -s .fifo $flog_fifo`.flog.pid"
fi
echo "Enabling logging for $flog_fifo ($out_log, $out_pid)..."
echo "%%PREFIX%%/bin/flog $flog_args $out_log < $flog_fifo &"
%%PREFIX%%/bin/flog $flog_args $out_log < $flog_fifo &
echo $! > $out_pid
done
fi
}
rubyrep_stop() {
if [ -f "$pidfile" ] ; then
kill -9 `cat $pidfile`
rm $pidfile
else
echo "PID file not found ($pidfile)"
fi
}
rubyrep_poststop() {
if [ "$rubyrep_fifo_logs"="YES" ] ; then
for f in $stdout_log $stderr_log ; do
flog_fifo=$f
if [ "$cfgname" ] ; then
local out_pid="/var/run/`basename -s .fifo.$cfgname $flog_fifo`.$cfgname.flog.pid"
else
local out_pid="/var/run/`basename -s .fifo $flog_fifo`.flog.pid"
fi
kill $out_pid >/dev/null 2>/dev/null
rm $out_pid >/dev/null 2>/dev/null
done
fi
}
rubyrep_init() {
if [ "$rubyrep_multi" = "NO" ] ; then
cmdline="%%PREFIX%%/bin/rubyrep generate $rubyrep_config"
if [ "$1" = "init" -a -f "$rubyrep_config" ] ; then
echo "Skipping file $rubyrep_config (already exists)."
else
echo "Generating template file $rubyrep_config"
$cmdline
fi
else
echo 'Command not available when $rubyrep_multi="YES"'.
exit
fi
}
name="rubyrep"
rcvar=`set_rcvar`
# read configuration and set defaults
load_rc_config $name
extra_commands="init"
init_cmd="${name}_init"
command="/usr/sbin/daemon"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
stop_postcmd="${name}_poststop"
rubyrep_command_flags="$rubyrep_command_flags"
if [ "$rubyrep_multi" = "NO" ] ; then
stdout_log=${rubyrep_stdout_log}
stderr_log=${rubyrep_stderr_log}
log_args=">> ${stdout_log} 2>> ${stderr_log} "
cmdline="%%PREFIX%%/bin/rubyrep $rubyrep_command $rubyrep_command_flags -c $rubyrep_config"
pidfile="/var/run/$name.pid"
flags="-p ${pidfile} ${cmdline} ${log_args}"
run_rc_command "$1"
elif [ "$rubyrep_multi" = "YES" ] ; then
[ ! -d "$rubyrep_config_dir" ] && mkdir -p "$rubyrep_config_dir"
for i in `ls $rubyrep_config_dir/*.conf` ; do
rubyrep_config=$i
cfgname=$(basename -s .conf $i)
stdout_log=${rubyrep_stdout_log}.$cfgname
stderr_log=${rubyrep_stderr_log}.$cfgname
log_args=">> ${stdout_log} 2>> ${stderr_log} "
cmdline="%%PREFIX%%/bin/rubyrep $rubyrep_command $rubyrep_command_flags -c $rubyrep_config"
pidfile="/var/run/${name}_${cfgname}.pid"
flags="-p ${pidfile} ${cmdline} ${log_args}"
run_rc_command "$1"
done
fi
|