Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Apr 2022 16:30:20 +0200
From:      Axel Rau <Axel.Rau@Chaos1.DE>
To:        freebsd-hackers@freebsd.org
Subject:   rc script to let a service wait for db available
Message-ID:  <f6201772-d124-a08f-3623-25f1a6190faf@Chaos1.DE>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f6201772-d124-a08f-3623-25f1a6190faf>