Enable rc.local startup file on Debian 9 (Stretch)


chmod +x /etc/rc.local
systemctl start rc-local
systemctl status rc-local

 

 

 

 

The rc.local script is executed at boot time or when changing runlevels. Adding commands to the bottom of this script is an easy way to perform necessary tasks. However in Debian 9 it is removed by default, but you can add it back with a few steps.

1) Create file rc-local.service in /etc/systemd/system with the following content:

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

2) Create file rc.local in /etc with the following content:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

3) Add execute permissions to rc.local and enable the script:

chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service

4) Edit rc.local and add your content

Note: you can check the status (or errors) using the command

systemctl status rc-local.service