linux systemd:/etc/rcを有効にします.local

2088 ワード

詳細
1.ファイルrc-localを作成する.サービスファイル
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を表示します.サービスステータス
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.