Debian 9 Stretch 解决 /etc/rc.local 开机启动问题

来源: https://sb.sb/blog/debian-9-rc-local/

之前都是添加命令到 /etc/rc.local 但是Debain 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
$ systemctl start rc-local.service

再次查看状态:

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 2017-08-03 09:41:18 UTC; 14s ago
  Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Aug 03 09:41:18 xtom-hk systemd[1]: Starting /etc/rc.local Compatibility...
Aug 03 09:41:18 xtom-hk systemd[1]: Started /etc/rc.local Compatibility.

然后把需要开机启动的命令,添加到 /etc/rc.local文件中, 丢在exit 0 前面就可以了.

你可能感兴趣的:(Linux系统)