LoginSignup
4
6

More than 5 years have passed since last update.

Macの定期処理

Last updated at Posted at 2014-02-19

経緯

  • Macで動いているJenkinsさんのダッシュボードのCSSが壊れる
  • Jenkinsのwebroot以下のcssとかimgが消えている

    • /private/var/folders/q0/yzpjz6fn3k70x2yth9pdn830w3vyt7/T/jetty-0.0.0.0-8080-jenkins.war--any-/webapp
    • Jenkins起動時に確認

      INFO: Extract jar:file:/Applications/Jenkins/jenkins.war!/ to /private/var/folders/q0/yzpjz6fn3k70x2yth9pdn830w3vyt7/T/jetty-0.0.0.0-8080-jenkins.war--any-/webapp
      
  • Macの日次処理があやしい

  • Macの日次処理ってどうなってるんでしょう

環境

  • MacOS X 10.9.1

本題

  • Macの日次(週次・月次)処理は以下の用にcronに設定されている
com.apple.periodic-daily.plist
// com.apple.periodic-[daily|weekly|monthly].plist
$ cat /System/Library/LaunchDaemons/com.apple.periodic-daily.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.apple.periodic-daily</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/libexec/periodic-wrapper</string>
                <string>daily</string>
        </array>
        <key>LowPriorityIO</key>
        <true/>
        <key>Nice</key>
        <integer>1</integer>
        <key>LaunchEvents</key>
        <dict>
                <key>com.apple.xpc.activity</key>
                <dict>
                        <key>com.apple.periodic-daily</key>
                        <dict>
                                <key>Interval</key>
                                <integer>86400</integer>
                                <key>GracePeriod</key>
                                <integer>14400</integer>
                                <key>Priority</key>
                                <string>Maintenance</string>
                                <key>AllowBattery</key>
                                <false/>
                                <key>Repeating</key>
                                <true/>
                        </dict>
                </dict>
        </dict>
        <key>AbandonProcessGroup</key>
        <true/>
</dict>
</plist>
  • 手動で実行する
periodic
$ sudo periodic daily
$ sudo periodic weekly
$ sudo periodic monthly
  • logを確認する
log
$ less /var/log/daily.out
$ less /var/log/weekly.out
$ less /var/log/monthly.out
  • 実行されるscriptを確認する
script
// それぞれ以下のディレクトリにあるscriptが実行される 
/etc/periodic/daily
/etc/periodic/weekly
/etc/periodic/monthly

// configファイル
/etc/defaults/periodic.conf
  • userが処理を追加する
    • /etc/daily.localにshell scriptを追加
periodic.local
# 999.local
daily_local="/etc/daily.local"              # Local scripts
weekly_local="/etc/weekly.local"              # Local scripts
monthly_local="/etc/monthly.local"              # Local scripts

参考

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6