C.W.K.
Stream
Lesson 07 of 10 · published

Cron 과 launchd

~12 min · cron, launchd, schedule

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

스케줄링의 두 방법

Linux 서버에선 cron 이 역사적 스케줄러. macOS 는 cron 을 deprecate 하고 launchd 권장 — 서비스 매니저 + 스케줄러. 둘 다 살아 있지만 Mac 엔 launchd 가 정답.

cron 빠른 참조

crontab -e                 # cron 테이블 편집
crontab -l                 # 나열
*/5 * * * * /path/to/script.sh
0   3 * * 1 /path/to/weekly.sh

5 필드: 분 시 일 월 요일. cron 은 PATH 작은 stripped shell 에서 도라. 항상 절대 경로 + 필요한 거 명시 source: 0 3 * * * . $HOME/.zshenv && /path/to/script.sh.

launchd LaunchAgent

plist 를 ~/Library/LaunchAgents/ 에 두고 launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.me.mytask.plist 로 load. 스케줄은 StartInterval (초) 또는 StartCalendarInterval (cron 류 사전). 재부팅 후에도 살아 있고, 크래시 시 자동 재시작 지원.

<plist>
<dict>
  <key>Label</key>          <string>com.me.daily</string>
  <key>ProgramArguments</key> <array><string>/path/to/daily.sh</string></array>
  <key>StartCalendarInterval</key>
    <dict><key>Hour</key><integer>3</integer><key>Minute</key><integer>0</integer></dict>
  <key>StandardOutPath</key> <string>/tmp/daily.log</string>
</dict>
</plist>

Pippa 메모 — APScheduler in-process

Pippa heartbeat 스케줄은 cron 도 launchd 도 아니야. pippa serve 안의 APScheduler. launchd 의 역할은 pippa serve 를 살려두는 것 뿐. 스케줄 자체가 in-process 라 ergonomics 좋음. 그래서 office Mac 의 crontab -l 은 비어 있음 — 디자인.

어느 쪽?

  • Linux 서버 → cron (또는 systemd timer).
  • macOS → launchd LaunchAgent (사용자) / LaunchDaemon (root).
  • 앱 내 스케줄 → 스케줄러 임베드 (APScheduler, node-cron) + OS 가 프로세스 살림. 보통 가장 깔끔.

Code

launchd agent 부팅·bash
# Place plist
vim ~/Library/LaunchAgents/com.me.daily.plist
# Load (idempotent enough; bootout first if it was loaded)
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.me.daily.plist
# Inspect
launchctl list | grep com.me.daily
# Run now without waiting for schedule
launchctl kickstart gui/$UID/com.me.daily

External links

Exercise

작은 스크립트 (echo hello at $(date) >> /tmp/heartbeat.log) 골라. 스케줄: cron 의 */5 * * * * 또는 launchd plist StartInterval 300. /tmp/heartbeat.log tail 로 검증.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.