Why is the command in /etc/rc.local not executed during startup?
Solution 1:
rc.local
script exits if any error occurs while executing any of its commands (mention the -e
flag in #!/bin/sh -e
).
It is possible that some prerequisites are not met when you try to run your commands when rc.local
execution takes place, so your command execution fails.
I encountered the same thing while manually setting cpu governor and failing to do so in rc.local
. Here's my custom workaround, which uses update-rc.d
to make your commands run on startup:
- Create a file
myscript.sh
in directory/etc/init.d
with a heading:#!/bin/sh
- Put your custom commands as the content
- Make it executable:
sudo chmod +x /etc/init.d/myscript.sh
- Create symlinks for your script for various runlevels:
sudo update-rc.d myscript.sh defaults
Also, you could check /etc/network/if-up.d
scripts and see if you could trigger your commands when networking starts.
Solution 2:
Make sure the rc.local script is executable:
sudo chmod +x /etc/rc.local
Then, enable it:
sudo systemctl enable rc-local.service
Reboot the system or start the script manually by running:
sudo systemctl start rc-local.service
The service status can be displayed by running:
$ sudo systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (running) since Mon 2018-04-02 10:39:44 -03; 1s ago
Process: 2044 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
Main PID: 2049 (svscanboot)
Tasks: 3
Memory: 556.0K
CPU: 10ms
CGroup: /system.slice/rc-local.service
Solution 3:
i had some similar problem in rc.local not executing at startup
sshades provided me with the following answer :
Ubuntu is now using systemd, and rc.local is now considered a service which is turned "off" by default. You can turn rc.local "on" by entering the following command and rebooting:
sudo systemctl enable rc-local.service
https://askubuntu.com/a/770033/395498
although i haven't tested his solution i think it sounds logical and will work. However :
I also found a solution that adding a script to ./.config/autostart-scripts/ will do the trick
Solution 4:
try sudo sysv-rc-conf
and check out if rc.local
is enabled
rc.local [ ] [x] [x] [x] [x] [ ] [ ] [ ]
Solution 5:
We had this problem on some hosted servers loading FW rules.
On these boxes they reboot VERY quickly and we found just putting a "sleep 1" in rc.local before the load statements seems to fix the issue. I guess it gave a little time for the interfaces to settle before loading the FW rules.