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
|
#!/bin/sh -eu
usage () {
cat << EOF >&2
Program /lib/runit/invoke-run must only be used as interpreter for
run scripts with full path.
Please, refer to documentation in manual page invoke-run(5). If error
persist, file bug report aganist 'runit' Debian package.
EOF
}
if [ $# = 0 ] ; then
usage
exit 1
fi
#sane runit service directory?
if [ ! -x "${PWD}"/run ]; then
echo "invoke-run: error: ${PWD}/run does not exists or not executable"
usage
exit 1
fi
if [ -f "/etc/sv/${PWD##*/}/.meta/installed" ] ; then
# uninstalled, but not purged. See #929693 and commit [4c485b] in dh-runit repository.
if ! [ -f "/usr/share/runit/meta/${PWD##*/}/installed" ] ; then
if ! [ -d "/usr/share/runit/sv/${PWD##*/}" ]; then
echo "invoke-run: ${PWD##*/} binary not installed"
sv down "${PWD##*/}"
exit 0
fi
fi
fi
if [ -r "${PWD}/.meta/bin" ] ; then
if [ ! -e "$(cat ${PWD}/.meta/bin)" ]; then
echo "invoke-run: ${PWD##*/} binary not installed"
sv down "${PWD##*/}"
else
stat -c %W "$(cat ${PWD}/.meta/bin)" > "${PWD}/.meta/wtime"
fi
fi
if [ -r "/etc/default/${PWD##*/}" ] ; then
# export all assigned variables, allow references to
# undefined variables.
set -a +u
. "/etc/default/${PWD##*/}"
set +a -u
fi
if [ -x "/etc/init.d/${PWD##*/}" ] ; then
# Stopping some services (e.g display manager) is disruptive
# and must be done only manually by user.
if [ -f "/usr/share/runit/meta/${PWD##*/}/noreplace" ] || \
[ -f "${PWD}/.meta/noreplace" ] ; then
if "/etc/init.d/${PWD##*/}" status >/dev/null 2>&1 ; then
sv down "${PWD##*/}"
exit 0
fi
fi
if [ ! -h "/etc/init.d/${PWD##*/}" ] && [ ! -h /sbin/start-stop-daemon ]; then
# don't stop the script if it's a symlink: it's likely to /usr/bin/sv/
"/etc/init.d/${PWD##*/}" stop >/dev/null
fi
fi
XCHPST=""
if [ -x /usr/bin/xchpst ]; then
#if [ -r "${PWD}/xchopts" ] && [ ! -e "${PWD}/.xchopts" ] ; then
if [ -r "${PWD}/xchopts" ] ; then
export XCHPST="xchpst --file ${PWD}/xchopts"
fi
fi
if [ -e /etc/runit/verbose ]; then
echo "invoke-run: starting ${PWD##*/}"
fi
if [ -d "${PWD}/env" ] ; then
exec chpst -e "${PWD}/env" -- /bin/sh "${PWD}"/run
else
exec /bin/sh "${PWD}"/run
fi
|