Systemd Timer Daemon 서비스 추가

입질쾌감 물때표

Gentoo 배포판 기준으로 작성됨. systemd 기준으로 기준시간 단위 별로 뭔가를 실행시켜야 할 때에는 timer 서비스를 추가해서 동작되게 만들어준다.

vi /etc/systemd/system/monitor.service

[Unit]
Description=Logs system statistics to the systemd journal
Wants=myMonitor.timer

[Service]
Type=oneshot
ExecStart=/usr/bin/free # 실행시키고자 하는 스크립트

[Install]
WantedBy=multi-user.target

타이머를 추가했으면 상태확인을 해본다.

# systemctl status monitor.service
○ monitor.service - Logs system statistics to the systemd journal
     Loaded: loaded (/etc/systemd/system/monitor.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Mon 2023-07-03 11:05:51 KST; 4min 43s ago
TriggeredBy: ● monitor.timer
   Main PID: 1673 (code=exited, status=0/SUCCESS)
        CPU: 12ms

journalctl로 모니터링을 하게 되면 각 서비스별 로그 내용을 실시간으로 확인이 가능함

# journalctl -S today -f -u monitor.service # 서비스 로그 확인 tail -f 와 유사
vi /etc/systemd/system/monitor.timer

[Unit]
Description=Logs system statistics to the systemd journal
Wants=myMonitor.timer

[Service]
Type=oneshot
ExecStart=/usr/bin/free

[Install]
WantedBy=multi-user.target

OnCalendar의 필드에 스케쥴을 기재하면 되는데, 예를 들어,
2022-6,7,8-1,15 01:15:00” 인 경우에는 “2022년 – 6,7,8월 – 1, 15일 – 01:15:00 실행” 한다는 의미를 갖는다.
이에 대한 유효성 검사를 할수 있는데, 아래와 같이 커맨드로 실행 테스트를 할수 있다.

systemd-analyze calendar "2022-6,7,8-1,15 01:15:00"

날짜 영역은 반드시 “로 묶어야 함

[기타]
*-*-* 00:15:30 : 매일 15:30에 실행
Weekly : 매일 월요일 실행 (아래의 설정도 동일하다)
    > Mon *-*-* 00:00:00
    > Mon

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다