File: /srv/admin/scripts/init-lib.sh
#!/bin/bash -e
export LOGROTATE_CONF="${CUSTOMER_DIR}/var/admin/logrotate.conf"
wait_for_pidfile() {
local i=0
while [ "$i" -lt 20 ]; do
case "$1" in
'created') [ -f "$2" ] && return 0 ;;
'removed') [ -f "$2" ] || return 0 ;;
esac
echo -n .
i=$((i + 1))
sleep 1
done
return 1
}
foreach_daemon() {
local force=0
local doublecheck=0
# if daemon is *unset* it will be declared as local, otherwise it won't,
# allowing the caller function to get the daemon value.
#
# caller() {
# local daemon=
# foreach_daemon status || echo "$daemon is down"
# }
[ -z "${daemon+dummy}" ] && local daemon
while true; do
case "$1" in
--force) force=1; shift ;;
--doublecheck) doublecheck=1; shift ;;
*) break ;;
esac
done
for daemon in $DAEMONS; do
for i in {1,2}; do
"/srv/admin/scripts/init.d/$daemon" "$@" || {
retval="$?"
if [ "$doublecheck" -eq 1 -a "$i" -eq 1 ]; then
echo "$daemon $@ exited with code $retval, doublechecking..."
sleep 1
continue
fi
[ "$force" -eq 0 ] && return 1
}
break
done
done
}