본문 바로가기

리눅스

[리눅스] ubuntu rc.local 활성화하기

728x90

ubuntu rc.local 활성화하기

테스트 환경

$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

rc.local 활성화하기

rc-local 서비스 확인

systemctl status rc-local.service
$ systemctl status rc-local.service
○ rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)

/etc/rc.local 파일 생성

printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
$ printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
#!/bin/bash
exit 0

/etc/rc.local 실행 권한 부여

chmod +x /etc/rc.local
$ cat /etc/rc.local
#!/bin/bash
exit 0
$ ls -l /etc/rc.local 
-rwxr-xr-x 1 root root 19 Oct 21 13:02 /etc/rc.local

rc-local.service(/lib/systemd/system/rc-local.service) 파일 편집

cat /lib/systemd/system/rc-local.service
$ cat /lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

아래 내용 추가

cat << EOF >> /lib/systemd/system/rc-local.service

[Install]
WantedBy=multi-user.target
EOF
$ cat /lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

rc.local 활성화 및 서비스 시작

systemctl --now enable rc-local
$ systemctl --now enable rc-local                   
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.
systemctl status rc-local
$ systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Fri 2022-10-21 13:09:33 KST; 3min 57s ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 5330 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
        CPU: 2ms

Oct 21 13:09:33 replydb-245 systemd[1]: Starting /etc/rc.local Compatibility...
Oct 21 13:09:33 replydb-245 systemd[1]: Started /etc/rc.local Compatibility.
728x90