IT Technology/Linux

Linux 부팅시 스크립트 자동 실행 방법

by빵수 2024. 4. 17. 13:25
728x90
반응형

Linux 부팅시 스크립트 자동 실행 방법에 대해서 알아보자.

 

 

Centos 7 버전 이상에서 서버가 재기동 될 시 명령어를 자동 실행하여 서비스를 실행 시킬 수 있으다.

자동으로 실행하게 하려면 "/etc/rc.d/rc.local" 파일을 이용하면 된다.

 

1. rc.local 실행권한 허용

#chmod +x /etc/rc.d/rc.local

 

 

2. 실행스크립트 추가

 

#vi /etc/rc.d/rc.local


#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/artemis-2.32.0/bin/localhost/bin/artemis-service start

 

3. rc.local 서비스 활성화

vi lib /systemd/system/rc-local.service

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

 

 

4. rc.local 서비스 시작, 상태확인

 

상태 확인 명령어 : systemctl status rc-local.service

서비스 중단 명령어 : systemctl stop rc-local.service

서비스 시작 명령어 : systemctl start rc-local.service

서비스 자동 재시작 명령어 : systemctl enable rc-local.service

반응형