본문 바로가기
Linux/Linux Shell Command

부팅 시 프로그램 자동 실행하기

by 드로니뚜벅이 2023. 8. 8.

리눅스 시스템 부팅 시에 내가 원하는 프로그램을 자동 실행하기 위한 방법을 알아보겠습니다.

 

서비스(service) 파일 생성

$ vi myprogram.service

아래처럼 세 개의 섹션으로 구성된 파일을 작성합니다.

[Unit]
Description=My Service Program
After=network.target

[Service]
ExecStart=/home/run/services/myprogram
WorkingDirectory=/home/run/services
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root

[Install]
WantedBy=multi-user.target

 

서비스 파일 복사

$ sudo cp myprogram.service /etc/systemd/system

 

서비스 등록

$ sudo systemctl enable myprogram.service
$ sudo systemctl start myprogram.service

 

서비스 삭제

$ sudo systemctl stop myprogram.service    # 서비스 중지
$ sudo systemctl disable myprogram.service # 서비스 제거

 

서비스 상태 확인

$ sudo systemctl status myprogram.service

 

 

참고사이트

 

'Linux > Linux Shell Command' 카테고리의 다른 글

du - 리눅스 디스크 사용량 확인  (1) 2023.09.09
screen - 리눅스 가상 터미널  (0) 2023.08.15
watch - 시스템 모니터링  (0) 2023.06.19
zip 압축  (0) 2023.06.15
7z 압축  (0) 2023.06.15