1

I am loading a c binary using launchd service. It should be relaoded every time when system restarts. Below is my plist file:

<?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.example</string>
<key>ProgramArguments</key>
<array>
    <string>/etc/example/usr/sbin/example_cbinary</string>
</array>
<key>RunAtLoad</key>
    <true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>

Some times, it is exiting with 78 exit code.

launchctl list | grep example
-   78  com.example

I am unable to find root cause for this. As this happens once in hundred times. To resolve this i am unloading and loading this service. I wanted it to automatically unload and load whenever it exits with 78 status.

Any help is highly appreciable

Thanks in Adavance

1 Answer 1

0

I know it is an old article, but I had the same problem and could solve it by writing a python script which grep the 78 and call a system command e.g. shell script to unload and load the service. And put this script in crontab

pseudocode:

#!/bin/bash

export PATH=(your_$PATH)

    erg = `launchctl list | grep example | grep 78`
    if [ $erg = '78']
    then
        launchctl unload /Library/LaunchDeamons/example.plist
        launchctl load /Library/LaunchDeamons/example.plist
        # perhaps also
        launchctl start example
    fi 
       

And if that script will be executed correctly on the shell then put it into the crontab.

example cron entry:

* * * * * reload_example.sh (watch out for access rights and the new shitty security options)

Perhaps it is a usefull hint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.