linux systemd: 启用/etc/rc.local

1.创建文件rc-local.service文件

sudo vi /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.创建rc.local文件(如果不存在的话)

sudo vi /etc/rc.local

   

    文件内容举例

#!/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  

    确保rc.local可执行

sudo chmod +x /etc/rc.local

3.启用rc-local.service

sudo systemctl enable rc-local
sudo systemctl start rc-local.service

    查看rc-local.service状态

sudo systemctl status rc-local.service

    正常情况下得到类似的输出

hadoop@rick-ubuntu:/etc$ sudo systemctl status rc-local.service
? rc-local.service - /etc/rc.local Compatibility
   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 Tue 2017-06-20 18:11:15 CST; 3s ago
  Process: 27999 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

6? 20 18:11:15 rick-ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
6? 20 18:11:15 rick-ubuntu systemd[1]: Started /etc/rc.local Compatibility.

猜你喜欢

转载自rickgong.iteye.com/blog/2380656