~ubuntu-branches/debian/experimental/sysvinit/experimental

« back to all changes in this revision

Viewing changes to debian/src/sysv-rc/sbin/invoke-rc.d

  • Committer: Package Import Robot
  • Author(s): Roger Leigh, Roger Leigh, Michael Stapelberg
  • Date: 2012-07-28 20:09:11 UTC
  • mfrom: (9.1.47 sid)
  • Revision ID: package-import@ubuntu.com-20120728200911-1xa3ydm5a46lyrjd
Tags: 2.88dsf-41+jessie1
[ Roger Leigh ]
* initscripts:
  - Move /etc/nologin and /var/lib/initscripts/nologin to
    /run/nologin.  This means that nologin is always created on
    a writable, available filesystem.  Closes: #660862.
  - Remove code to generate /etc/mtab.  /etc/mtab is now always a
    symbolic link to /proc/mounts.  Closes: #630723.
  - Remove incorrect use of break in case blocks in vars.sh.  Thanks
    to Raphaël Hertzog for this patch.  Closes: #701031.
  - /etc/network/if-up.d/mountnfs: Skip lo if already configured.
    Closes: #705052.  Thanks to Timo Weingärtner.
* sysvinit:
  - Document length limit of 127 in inittab process field.  Thanks
    to Johannes Truschnigg.  Closes: #693960.
* sysv-rc:
  - Fix typo in invoke-rc.d(8).  Closes: #683804.  Thanks to
    Martin-Éric Racine.

[ Michael Stapelberg ]
* systemd: update check to look for /run/systemd/system.
  Closes: #703571
* sysv-rc:
  - Add systemd support to update-rc.d(8) and invoke-rc.d(8).
    Closes: #683084.
  - service(8): use systemctl on machines that run systemd.
    Closes: #704923

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
RUNLEVEL=/sbin/runlevel
25
25
POLICYHELPER=/usr/sbin/policy-rc.d
26
26
INITDPREFIX=/etc/init.d/
 
27
UPSTARTDIR=/etc/init/
27
28
RCDPREFIX=/etc/rc
28
29
 
29
30
# Options
36
37
RETRY=
37
38
RETURNFAILURE=
38
39
RC=
 
40
is_upstart=
 
41
is_systemd=
39
42
 
40
43
# Shell options
41
44
set +e
265
268
        ;;
266
269
esac
267
270
 
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" ]
 
275
then
 
276
    is_upstart=1
 
277
elif test -d /run/systemd/system ; then
 
278
    is_systemd=1
 
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.
272
283
    exit 100
273
284
fi
375
386
esac
376
387
 
377
388
# test if /etc/init.d/initscript is actually executable
378
 
if testexec "${INITDPREFIX}${INITSCRIPTID}" ; then
 
389
_executable=
 
390
if [ -n "$is_upstart" ]; then
 
391
    _executable=1
 
392
elif [ -n "$is_systemd" ]; then
 
393
    _state=$(systemctl -p LoadState show "${INITSCRIPTID}.service" 2>/dev/null)
 
394
    if [ "$_state" != "LoadState=masked" ]; then
 
395
        _executable=1
 
396
    fi
 
397
elif testexec "${INITDPREFIX}${INITSCRIPTID}"; then
 
398
   _executable=1
 
399
fi
 
400
if [ "$_executable" = "1" ]; then
379
401
    if test x${RC} = x && test x${MODE} = xquery ; then
380
402
        RC=105
381
403
    fi
422
444
    ACTION="$@"
423
445
}
424
446
 
 
447
if [ -n "$is_upstart" ]; then
 
448
    RUNNING=
 
449
    DISABLED=
 
450
    if status "$INITSCRIPTID" 2>/dev/null | grep -q ' start/'; then
 
451
        RUNNING=1
 
452
    fi
 
453
    UPSTART_VERSION_RUNNING=$(initctl version|awk '{print $3}'|tr -d ')')
 
454
 
 
455
    if dpkg --compare-versions "$UPSTART_VERSION_RUNNING" ge 0.9.7
 
456
    then
 
457
        initctl show-config -e "$INITSCRIPTID"|grep -q '^  start on' || DISABLED=1
 
458
    fi
 
459
fi
 
460
 
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
430
466
        RC=102
431
467
        setechoactions ${ACTION}
432
468
        while test ! -z "${ACTION}" ; do
435
471
                printerror executing initscript action \"${saction}\"...
436
472
            fi
437
473
 
438
 
            "${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
 
474
            if [ -n "$is_upstart" ]; then
 
475
                case $saction in
 
476
                    status)
 
477
                        "$saction" "$INITSCRIPTID" && exit 0
 
478
                        ;;
 
479
                    start|stop)
 
480
                        if [ -z "$RUNNING" ] && [ "$saction" = "stop" ]; then
 
481
                            exit 0
 
482
                        elif [ -n "$RUNNING" ] && [ "$saction" = "start" ]; then
 
483
                            exit 0
 
484
                        elif [ -n "$DISABLED" ] && [ "$saction" = "start" ]; then
 
485
                            exit 0
 
486
                        fi
 
487
                        $saction "$INITSCRIPTID" && exit 0
 
488
                        ;;
 
489
                    restart)
 
490
                        if [ -n "$RUNNING" ] ; then
 
491
                            stop "$INITSCRIPTID"
 
492
                        fi
 
493
 
 
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
 
501
                            exit 0
 
502
                        fi
 
503
                        start "$INITSCRIPTID" && exit 0
 
504
                        ;;
 
505
                    reload|force-reload)
 
506
                        reload "$INITSCRIPTID" && exit 0
 
507
                        ;;
 
508
                    *)
 
509
                        # This will almost certainly fail, but give it a try
 
510
                        initctl "$saction" "$INITSCRIPTID" && exit 0
 
511
                        ;;
 
512
                esac
 
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
 
519
                fi
 
520
                case $saction in
 
521
                    start|stop|restart|status)
 
522
                        systemctl "${saction}" "${INITSCRIPTID}.service" && exit 0
 
523
                        ;;
 
524
                    reload)
 
525
                        _canreload="$(systemctl -p CanReload show ${INITSCRIPTID}.service 2>/dev/null)"
 
526
                        if [ "$_canreload" = "CanReload=no" ]; then
 
527
                            "${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
 
528
                        else
 
529
                            systemctl reload "${INITSCRIPTID}.service" && exit 0
 
530
                        fi
 
531
                        ;;
 
532
                    force-stop)
 
533
                        systemctl --signal=KILL kill "${INITSCRIPTID}.service" && exit 0
 
534
                        ;;
 
535
                    force-reload)
 
536
                        _canreload="$(systemctl -p CanReload show ${INITSCRIPTID}.service 2>/dev/null)"
 
537
                        if [ "$_canreload" = "CanReload=no" ]; then
 
538
                           systemctl restart "${INITSCRIPTID}.service" && exit 0
 
539
                        else
 
540
                           systemctl reload "${INITSCRIPTID}.service" && exit 0
 
541
                        fi
 
542
                        ;;
 
543
                    *)
 
544
                        # We try to run non-standard actions by running
 
545
                        # the init script directly.
 
546
                        "${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
 
547
                        ;;
 
548
                esac
 
549
            else
 
550
                "${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
 
551
            fi
439
552
            RC=$?
440
553
 
441
554
            if test ! -z "${ACTION}" ; then