Debian 9 Stretch 해결/etc/rc.질문

4738 단어 Linux 시스템
출처:https://sb.sb/blog/debian-9-rc-local/
이전에는/etc/rc.에 명령을 추가했습니다.local 하지만 Debain 9에는/etc/rc.가 기본적으로 포함되지 않습니다.local 파일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 앞에 잃어버리면 됩니다.

좋은 웹페이지 즐겨찾기