Perfect solution without rc. local file in Linux
- 2021-07-01 08:31:27
- OfStack
Newer Linux releases no longer have rc. local files. Because it has been serviced.
Solution:
1. Set rc-local. service
sudo vim /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
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
2. Activate rc-local. service
sudo systemctl enable rc-local.service
3. Add startup service
Manually create or copy existing ones
/etc/rc.local
And give execution permission
#!/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.
# The following is the command to boot
/home/selfcs/anaconda3/bin/python /home/selfcs/t.py > /home/selfcs/auto.log
exit 0
# Give script execution permission
sudo chmod +x /etc/rc.local
Summarize