1

I am trying to use PathState to start and stop a daemon on Mac OSX. It start when I create a file called /var/cache/myjob/run. However when the file is removed, the daemon doesn't stop again.

How do you use PathState to make it stop?

The launch configuration

<?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>StandardOutPath</key>
        <string>/var/log/tomcat/server.log</string>
        <key>StandardErrorPath</key>
        <string>/var/log/tomcat/server.log</string>
        <key>Label</key>
        <string>com.clcbio.clcserver</string>
        <key>WorkingDirectory</key>
        <string>/Users/tomcat/tomcatdist</string>
        <key>GroupName</key>
        <string>daemon</string>
        <key>KeepAlive</key>
        <dict>
            <key>PathState</key>
            <dict>
                <key>/var/cache/tomcat/run</key>
                <true />
            </dict>
        </dict>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/bash</string>
            <string>-c</string>
            <string>java -Xmx512m -XX:MaxPermSize=192m -Djava.awt.headless=true
                -Djava.library.path=./native
                -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
                -Djava.util.logging.config.file=./conf/logging.properties
                -Djava.endorsed.dirs=./endorsed -Dcatalina.base=./
                -Dcatalina.home=./ -cp bin/bootstrap.jar:./conf
                org.apache.catalina.startup.Bootstrap</string>
        </array>
        <key>UserName</key>
        <string>tomcat</string>
    </dict>
</plist>
Erik Martino
  • 113
  • 4

1 Answers1

0

You can't do that with a launchd item. A launchd item specifies the conditions under which a program should be started (and maybe restarted if it exits), but not the conditions under which it should be stopped. You'll need to use some other mechanism to stop the process. (Note that you can stop a running daemon with e.g. sudo launchctl stop com.clcbio.clcserver)

Gordon Davisson
  • 11,036
  • 3
  • 27
  • 33
  • > If the value of the key is true, then the job will be kept alive as > long as the path exists. It will take 3-4 seconds to stop the job. No need to use `launchctl` stop or unload command. – Parag Bafna Oct 16 '13 at 12:11