Debian 9 – Executando scripts na inicialização usando rc.local
No Debian 9, o famoso e tradicional “rc.local” foi descontinuado.
Você que é usuário ou administrador linux há uma forma de você reviver o rc.local usando o SystemD.
Abaixo, mostro como você deve proceder para ativar seu rc.local.
- Crie um arquivo “rc-local.service“:
nano /etc/systemd/system/rc-local.service
- Adicione o conteúdo abaixo no arquivo que voce está criando e editando no momento:
[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
- Crie e edite o arquivo “rc.local“:
nano /etc/rc.local
- Insira o conteúdo em seu rc.local:
#!/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
- Altere a permissão do arquivo para execução:
chmod +x /etc/rc.local
- Inicie o script rc-local no boot:
systemctl start rc-local.service
- Verifique se ocorreu algum erro quando você iniciou o serviço com o comando:
systemctl status rc-local.service