Debian 9.x “stretch” 解決 /etc/rc.local 開機啟動問題

Debian 9.x “stretch” 解決 /etc/rc.local 開機啟動問題

由於某些軟體並沒有增加開啟啟動的服務,很多時候需要手工添加,一般我們都是推薦添加命令到 /etc/rc.local 文件,但是 Debian 9 默認不帶 /etc/rc.local 文件,而 rc.local 服務卻還是自帶的

root@debian9 ~ # cat /lib/systemd/system/rc.local.service

#  This file is part of systemd.

#

#  systemd is free software; you can redistribute it and/or modify it

#  under the terms of the GNU Lesser General Public License as published by

#  the Free Software Foundation; either version 2.1 of the License, or

#  (at your option) any later version.

 

# This unit gets pulled automatically into multi-user.target by

# systemd-rc-local-generator if /etc/rc.local is executable.

[Unit]

Description=/etc/rc.local Compatibility

ConditionFileIsExecutable=/etc/rc.local

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no

並且默認情況下這個服務還是關閉的狀態

root@debian9 ~ # systemctl status rc-local

  • rc-local.service – /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: inactive (dead)

為了解決這個問題,我們需要手工添加一個 /etc/rc.local 文件

cat <<EOF >/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

EOF

然後賦予許可權

chmod +x /etc/rc.local

接著啟動 rc-local 服務

systemctl start rc-local

再次查看狀態

root@debian9 ~ # systemctl status rc-local

  • rc-local.service – /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: active (exited) since Thu 2018-03-01 09:45:18 UTC; 14s ago

Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

 

Aug  09:45:18 xtom-proxy systemd[1]: Starting /etc/rc.local Compatibility…

Aug 03 09:45:18 tom-proxy systemd[1]: Started /etc/rc.local Compatibility.

然後你就可以把需要開機啟動的命令添加到 /etc/rc.local 文件,放在 exit 0 前面即可,並嘗試重啟以後試試是否生效

參考資料: Where is rc.local in Debian 9 (Debian Stretch)
https://stackoverflow.com/questions/44797694/where-is-rc-local-in-debian-9-debian-stretch

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營