haylocki
Posts: 11
Joined: Tue Nov 11, 2014 7:24 am

systemd rc.local replacement

Wed Jan 13, 2016 1:29 pm

When running Minibian Jessie I discovered that entries that I put into /etc/rc.local were not having any effect.

The cause of this is that due to the parallel nature of systemd. So the commands in /etc/rc.local were being executed before the required hardware was setup.

To fix this problem it is necessary to create a systemd unit file that runs when the system becomes idle (i.e. after the boot process has completed.)

To do this:

create the following file:

/lib/systemd/system/myscript.service

and put the following lines into it:

Code: Select all

Description=My Script Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/bin/bash /root/startup.sh

[Install]
WantedBy=multi-user.target
Then set the correct permissions on the file:

Code: Select all

chmod 644 /lib/systemd/systemmyscript.service
Now you need to add the script to systemd:

Code: Select all

systemctl daemon-reload
systemctl enable myscript.service
then create the file:

/root/startup.sh

and add the commands that you normally add to /etc/rc.local. Then reboot and your commands should be executed as expected.

This was shamelessly stolen from this article :

http://www.raspberrypi-spy.co.uk/2015/1 ... g-systemd/

Cheers, Ian

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: systemd rc.local replacement

Wed Jan 13, 2016 1:34 pm

Why mode 644?

I know what that means, and I'm sure it works (I'm not questioning that), but I am questioning whether it is necessary. What other mode value might the file have?
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

Return to “Troubleshooting”