Replacement for rc.local
rc.local is a very convenient method of firing off a process when the system is booted. It is being phased out.
To replace it you can do the following:
create a file named /usr/lib/systemd/system/StartupService.serviceĀ
[Service] Type=forking TimeoutSec=0 RemainAfterExit=yes ExecStart=/usr/local/sbin/StartupScript start [Unit] Description=rc.local replacement
CondidtionFileIsExecutable=/usr/local/sbin/StartupScript After=network-online.target Wants=network-online.target
[Install] WantedBy=multi-user.target
create a script /usr/local/sbin/StartupScript with whatever binary or script you want to run on boot example:
#!/bin/bash # this machine is on dhcp so I want to know what the ip address is when it boots /usr/bin/ifconfig | mail -s "My Test Box IP" my@myemail.com # I want to make sure wake on lan is turned up /usr/sbin/ethtool -s enp3s0 wol g
make sure it set to be executed
chmod 755 /usr/local/sbin/StartupScript
now execute:
systemctl enable StartupService
fyi: In /usr/lib/systemd/system/StartupService.service the lines:
After=network-online.target Wants=network-online.target
causes it to wait to start the targeted script until after the network is started
This was tested on Fedora 33