- Introducción (Volver al índice General)
Si os habéis encontrado en la situación de tener que añadir algunas líneas al archivo /etc/rc.local, y estáis utilizando la distribución Debian 9 Stretch, habréis podido comprobar que Debian ya no utiliza dicho archivo, ha quedado en desuso.Sin embargo, seguimos encontrando soluciones o mejoras para nuestro sistema que necesitan utilizar el archivo /etc/rc.local.
En este artículo, mostraremos la forma de habilitar el archivo rc.local en unos cuantos pasos, creando un servicio administrado por systemd y gestionado por la utilidad systemctl.
NOTA: Aunque no lo hemos probado, pensamos que la forma de habilitar rc.local que vamos a mostrar en este artículo, debería de funcionar para cualquier sistema Linux en el que ya no se utilice rc.local y se utilice systemd.
- Pasos para habilitar /etc/rc.local (Volver al índice General)
A continuación enumeraremos los pasos a seguir para habilitar el archivo rc.local.- Crear el archivo inexistente rc-local.service (Volver al índice General)
Este archivo tendremos que crearlo en el directorio /etc/systemd/system/. Para crearlo podemos utilizar el siguiente comando:$ sudo nano /etc/systemd/system/rc-local.service
A continuación, añadimos las siguientes líneas y guardamos el archivo:
[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
- Crear el archivo inexistente rc.local (Volver al índice General)
Este archivo tendremos que crearlo en el directorio /etc/. Para crearlo podemos utilizar el siguiente comando:$ sudo nano /etc/rc.local
A continuación, añadimos las siguientes líneas al archivo, que son el contenido genérico del archivo, y guardamos el archivo:
#!/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
- Cambiar los permisos al archivo /etc/rc.local (Volver al índice General)
Para cambiar los permisos al archivo /etc/rc.local utilizaremos el siguiente comando:$ sudo chmod +x /etc/rc.local
- Habilitar el script rc-local.service en el arranque (Volver al índice General)
Para habilitarlo en el arranque, utilizaremos el siguiente comando:$ sudo systemctl enable rc-local
- Arrancamos el script rc-local.service (Volver al índice General)
Para arrancarlo, utilizaremos el siguiente comando:$ sudo systemctl start rc-local.service
- Comprobar el estado del servicio (Volver al índice General)
Comprobamos si ha habido algún error en el arranque del servicio con el siguiente comando:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
sudo systemctl status rc-local.service ● rc-local.service - /etc/rc.local Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/rc-local.service.d └─debian.conf Active: active (exited) since Sat 2019-09-21 03:21:39 CEST; 9h ago Tasks: 0 (limit: 19660) CGroup: /system.slice/rc-local.service sep 21 03:21:39 deb9 systemd[1]: Starting /etc/rc.local... sep 21 03:21:39 deb9 systemd[1]: Started /etc/rc.local. sep 21 03:27:55 deb9 systemd[1]: [/etc/systemd/system/rc-local.service:11] Support for option SysVStartPriority= has been removed and it is i sep 21 03:32:32 deb9 systemd[1]: [/etc/systemd/system/rc-local.service:11] Support for option SysVStartPriority= has been removed and it is i sep 21 10:34:25 deb9 systemd[1]: [/etc/systemd/system/rc-local.service:11] Support for option SysVStartPriority= has been removed and it is i sep 21 10:35:02 deb9 systemd[1]: [/etc/systemd/system/rc-local.service:11] Support for option SysVStartPriority= has been removed and it is i sep 21 11:20:15 deb9 systemd[1]: [/etc/systemd/system/rc-local.service:11] Support for option SysVStartPriority= has been removed and it is i lines 1-15/15 (END)
Podemos observar en la salida del comando anterior que; en la línea 3 nos muestra que el servicio está cargado, y la línea 6 nos muestra que está activo.
- Crear el archivo inexistente rc-local.service (Volver al índice General)
Ahora ya podemos añadir las líneas necesarias para ejecutar aplicaciones o scripts desde el archivo rc.local a la antigua usanza.
Deja una respuesta