🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Yasushi Shinjo Thu, 27 Aug 2020 09:39
macOS 起動時・終了時のスクリプト実行、launchctl で SIGTERM の捕捉
#1
Author: Yasushi Shinjo
Date: Thu, 27 Aug 2020 09:39
25 lines
2364 bytes
新城@筑波大学情報です。こんにちは。

macOS で起動時にスクリプトを実行するのは、面倒になっています。昔は、
rc.local に書けば簡単でした。最近の技としては、crontab の @reboot を使う
ことです。それは良いのですが、shutdown 時にスクリプトを実行したくなりま
した。それで探したら、こんなのが出てきました。

    https://stackoverflow.com/questions/24200924/run-a-script-only-at-shutdown-not-log-off-or-restart-on-mac-os-x
    Run a script only at shutdown (not log off or restart) on Mac OS X
    asked Jun 13 '14 at 8:30,  answered Nov 24 '14 at 10:45 by freedev

ここで使われている技には関心しました。

- 起動時にシェルスクリプトを実後する。これは launchctl でできる。
- シェルスクリプトは終了しない。tail -f /dev/null & して wait $! でシグ
  ナルを待つ。
- SIGTERM が飛んできたら trap で終了の関数を実行する。

よく見ると、man 5 launchd.plist には signal のことも書いてありました。

macOS もこの辺(rc周り)、もう少し簡単にして欲しい。asl (Apple System
Logger) はつらい。asl には勝てる気がしません。

\\ 新城 靖 (しんじょう やすし) \\
\\ 筑波大学 情報工学        \\
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads