I'm trying to create the equivalent to rc.local that runs last during startup, but to run first during shutdown.

I basically copy/pasted /etc/init.d/rc.local as the base template, and updated the header to be

#! /bin/sh
# Provides:          rc.shutdown
# Required-Start:
# Required-Stop:     $all
# Default-Start:
# Default-Stop:      0
# Short-Description: Executes rc.shutdown if exists
# Description:

However, when I run update-rc.d rc.shutdown enable, I get

update-rc.d: error: rc.shutdown Default-Start contains no runlevels, aborting.

This is a shutdown script and so would have no default start. Interestingly enough the file /etc/init.d/halt has the same header file, but there seems to be no problem there.

I'm using Debian 8.1

  • Halt and reboot have their own runlevels (perhaps listed in /etc/inittab) so perhaps set those runlevels in the header?
    – thrig
    Sep 16, 2015 at 18:12
  • What version of debian are you running? That matters quite a bit here, since all of the init stuff is in flux.
    – alienth
    Sep 16, 2015 at 21:04
  • I'm using Debian 8.1
    – Kousha
    Sep 16, 2015 at 21:08

1 Answer 1


Considering you're on 8.1, you can use systemd to get what you want here (not sure that is acceptable to you, but it'd do the job).

Here is an example of a unit file which will execute whatever you want at shutdown, before the normal shutdown stuff is executed:

Description=Run first at shutdown
Before=shutdown.target halt.target


You could place this file in /etc/systemd/system/runme.service, and enable it using systemctl enable /etc/systemd/system/runme.service. It will then automatically run before a shutdown or halt.

  • My only concern here is that I do have some other scripts that are working just fine, and they have been created using update-rc.d. So I feel uneasy to use two different approaches for the shutdown sequence ...
    – Kousha
    Sep 16, 2015 at 21:38
  • I hear ya. Alas, the sysvinit stuff does not operate the same way when systemd is installed and used as the default init system (as it is in 8.1). As we discovered in the other answer, the current runlevel 0 stuff in sysvinit is not intuitive and far from simple to setup.
    – alienth
    Sep 16, 2015 at 21:41
  • There is certainly a way to get it to work properly with sysvinit, but I'm not sure how to do so. halt's setup is not as simple as it seems on a dependency-based init system, and it interacts with several other init scripts. To get it to work properly, you're going to need to determine how the dependency-based stuff works in 8.1, and you may also need to consider how systemd interacts with the sysvinit stuff (since systemd is the main init).
    – alienth
    Sep 16, 2015 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .