본문 바로가기
Linux/Tips&News

Ubuntu 20.04 에서 rc.local 파일을 찾을 수 없어요

by 드로니뚜벅이 2022. 4. 24.

/etc/rc.local 스크립트 파일은 시스템이 부팅 후 가장 마지막에 실행됩니다. 그래서 리눅스 시스템 개발자분들이나 리눅스를 좀 한다 하시는 분들은 /etc/rc.local 파일에 자동 실행되어야 할 프로그램이나 부팅 이후에 필요한 작업을 추가합니다. 호랑이 담배피는 시절처럼 먼 얘기이긴 하지만 도스(DOS)를 사용해 본 경험이 있다면 AUTOEXEC.BAT 스크립트 파일과 비슷한 기능을 한다고 이해하시면 될 듯 합니다.

그런데, 언젠가부터 정확히는 Ubuntu 16.04 이후로 /etc/rc.local 스크립트 파일이 사라졌습니다. 그렇다고 해서 rc.local이 하던 기능이 사라진 건 아니고 시스템 서비스 레벨로 조정이 되었습니다.

즉, systemd에서 rc-local.service 로 지원이 되고 있습니다.

 

아래 예시는 /etc/rc.local 파일을 생성 후에 sytemd이 부팅 시에 서비스를 실행할 수 있도록 설정했습니다.

1) /etc/rc.local 작성

$ sudo vi /etc/rc.local

#!/bin/sh
echo `date +%F" "%T` "rc.local worked" >> /tmp/rc-local.log
exit 0

$ sudo chmod +x /etc/rc.local

 

2) systemctl 명령어로 부팅 후에 서비스할 수 있도록 설정

$ sudo systemctl edit --full rc-local

#  SPDX-License-Identifier: LGPL-2.1+
#
#  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

$ sudo reboot

 

시스템이 재시작하게 되면 /tmp/rc-local.log 파일이 생성된 걸 확인할 수 있으며 systemctl 명령어로 확인해 보면 rc-local.service가 정상적으로 실행된 걸 알 수 있습니다.

$ sudo systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/etc/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
    Drop-In: /lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Mon 2022-04-25 12:39:52 KST; 1min 29s ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 1431 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

 4월 25 12:39:52 mapit systemd[1]: Starting /etc/rc.local Compatibility...
 4월 25 12:39:52 mapit systemd[1]: Started /etc/rc.local Compatibility.

 

 

참고 사이트