본문 바로가기

IT/Software

[우분투] systemd를 사용해서 백그라운드 서비스 등록

반응형

일반적으로, systemd에서 사용되는 Unit 파일들은 /lib/systemd/system/에 저장되어 있다. 그러니 여기에 파일을 생성하면 된다.


샘플 유닛 파일

[Unit]

Description=Running a Java Jar package as a background service


[Install]

WantedBy=multi-user.target


[Service]

Type=simple

ExecStart=/usr/bin/java -jar /home/elex/MyApp.jar

WorkingDirectory=/data 

Restart=always

User=root


[Path]


my-app.service라는 이름으로 저장한다.


systemd 데몬을 재시작

systemctl daemon-reload


서비스를 등록

systemctl enable my-app.service


그 외 쓸만한 명령

systemctl start my-app

systemctl stop my-app

systemctl restart my-app

systemctl status my-app





https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

반응형