268
## Verifies if the given initscript ID is known
269
## For sysvinit, this error is critical
270
if test ! -f "${INITDPREFIX}${INITSCRIPTID}" ; then
271
# If we're running on upstart and there's an upstart job of this name, do
272
# the rest with upstart instead of calling the init script.
273
if which initctl >/dev/null && initctl version | grep -q upstart \
274
&& [ -e "$UPSTARTDIR/${INITSCRIPTID}.conf" ]
277
elif test -d /run/systemd/system ; then
279
elif test ! -f "${INITDPREFIX}${INITSCRIPTID}" ; then
280
## Verifies if the given initscript ID is known
281
## For sysvinit, this error is critical
271
282
printerror unknown initscript, ${INITDPREFIX}${INITSCRIPTID} not found.
377
388
# test if /etc/init.d/initscript is actually executable
378
if testexec "${INITDPREFIX}${INITSCRIPTID}" ; then
390
if [ -n "$is_upstart" ]; then
392
elif [ -n "$is_systemd" ]; then
393
_state=$(systemctl -p LoadState show "${INITSCRIPTID}.service" 2>/dev/null)
394
if [ "$_state" != "LoadState=masked" ]; then
397
elif testexec "${INITDPREFIX}${INITSCRIPTID}"; then
400
if [ "$_executable" = "1" ]; then
379
401
if test x${RC} = x && test x${MODE} = xquery ; then
447
if [ -n "$is_upstart" ]; then
450
if status "$INITSCRIPTID" 2>/dev/null | grep -q ' start/'; then
453
UPSTART_VERSION_RUNNING=$(initctl version|awk '{print $3}'|tr -d ')')
455
if dpkg --compare-versions "$UPSTART_VERSION_RUNNING" ge 0.9.7
457
initctl show-config -e "$INITSCRIPTID"|grep -q '^ start on' || DISABLED=1
425
461
## Executes initscript
426
462
## note that $ACTION is a space-separated list of actions
427
463
## to be attempted in order until one suceeds.
428
464
if test x${FORCE} != x || test ${RC} -eq 104 ; then
429
if testexec "${INITDPREFIX}${INITSCRIPTID}" ; then
465
if [ -n "$is_upstart" ] || testexec "${INITDPREFIX}${INITSCRIPTID}" ; then
431
467
setechoactions ${ACTION}
432
468
while test ! -z "${ACTION}" ; do
435
471
printerror executing initscript action \"${saction}\"...
438
"${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
474
if [ -n "$is_upstart" ]; then
477
"$saction" "$INITSCRIPTID" && exit 0
480
if [ -z "$RUNNING" ] && [ "$saction" = "stop" ]; then
482
elif [ -n "$RUNNING" ] && [ "$saction" = "start" ]; then
484
elif [ -n "$DISABLED" ] && [ "$saction" = "start" ]; then
487
$saction "$INITSCRIPTID" && exit 0
490
if [ -n "$RUNNING" ] ; then
494
# If the job is disabled and is not currently
495
# running, the job is not restarted. However, if
496
# the job is disabled but has been forced into
497
# the running state, we *do* stop and restart it
498
# since this is expected behaviour
499
# for the admin who forced the start.
500
if [ -n "$DISABLED" ] && [ -z "$RUNNING" ]; then
503
start "$INITSCRIPTID" && exit 0
506
reload "$INITSCRIPTID" && exit 0
509
# This will almost certainly fail, but give it a try
510
initctl "$saction" "$INITSCRIPTID" && exit 0
513
elif [ -n "$is_systemd" ]; then
514
if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
515
# If we are called by a maintainer script, chances are good that a
516
# new or updated sysv init script was installed. Reload daemon to
517
# pick up any changes.
518
systemctl daemon-reload
521
start|stop|restart|status)
522
systemctl "${saction}" "${INITSCRIPTID}.service" && exit 0
525
_canreload="$(systemctl -p CanReload show ${INITSCRIPTID}.service 2>/dev/null)"
526
if [ "$_canreload" = "CanReload=no" ]; then
527
"${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
529
systemctl reload "${INITSCRIPTID}.service" && exit 0
533
systemctl --signal=KILL kill "${INITSCRIPTID}.service" && exit 0
536
_canreload="$(systemctl -p CanReload show ${INITSCRIPTID}.service 2>/dev/null)"
537
if [ "$_canreload" = "CanReload=no" ]; then
538
systemctl restart "${INITSCRIPTID}.service" && exit 0
540
systemctl reload "${INITSCRIPTID}.service" && exit 0
544
# We try to run non-standard actions by running
545
# the init script directly.
546
"${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
550
"${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
441
554
if test ! -z "${ACTION}" ; then