rc script to let a service wait for db available
- Reply: Eugene Grosbein : "Re: rc script to let a service wait for db available"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 27 Apr 2022 14:30:20 UTC
Hi all,
I have this rc script:
- - -
meteoavg_wfphost="dbb3"
meteoavg_wfpuser="meteo"
meteoavg_wfpdb="operations"
#
#
. /etc/rc.subr
name="meteoavg"
rcvar=${name}_enable
command=/usr/local/bin/meteoavg
load_rc_config $name
: ${meteoavg_enable="NO"}
: ${meteoavg_flags=" -l syslog:daemon -s Chaos1"}
: ${meteoavg_pidfile="/var/run/meteoavg-Chaos1.pid"}
pidfile="${meteoavg_pidfile}"
##start_cmd="${name}_start"
stop_precmd="${name}_prestop"
meteoavg_start() {
/usr/local/bin/wait_for_pgsql.sh ${meteoavg_wfphost} \
${meteoavg_wfpuser} ${meteoavg_wfpdb} \
"/usr/local/bin/${name} ${meteoavg_flags} &"
}
meteoavg_prestop() {
/bin/pkill wait_for_pgsql.sh || /usr/bin/true
}
- - -
wait_for_pgsql.sh :
- - -
#!/bin/sh
host="$1"
user="$2"
db="$3"
start_cmd="$4"
while ! /usr/local/bin/psql -h $host -U $user -d $db -c 'SELECT 1;'
>/dev/null 2>&1; do
sleep 5
done
$start_cmd
- - -
The rc ignores the '&' and waits for wait_for_pgsql.sh to complete.
How can I let rc continue without waiting?
Any help appreciated,
Axel
--
PGP-Key: CDE74120 ☀ computing @ chaos claudius