简体   繁体   中英

Where is init folder in macs from where I can load my .conf file based jobs

I just migrated from linux, and trying to run one of my solutions in mac, at my linux i had a .conf files while was used to change the "run level" and start a supervisor job at the start of machine.

Is there a similar implementation somewhere at the mac as well, if not then what's the alternative.

my .conf based job was used to look like this

description "myJob"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
exec supervisord --nodaemon --configuration <path to my config file>

The closest equivalent on OS X would be a launch daemon -- a property list file in /Library/LaunchDaemons that tells launchd when to launch your program. If I understand what your .conf file does, the equivalent would be something like this:

<?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>local.myJob</string>
        <key>ProgramArguments</key>
        <array>
                <string>/path/to/your/script</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
</dict>
</plist>

Name that local.myJob.plist, put it in /Library/LaunchDaemons, set the owner to root and permissions to 644, and then either reboot or load it with sudo launchctl load /Library/LaunchDaemons/local.myJob.plist .

See man launchd.plist and Apple's developer document "Creating Launch Daemons and Agents" for more info and options. You can also look at the Apple-provided daemons in /System/Library/LaunchDaemons for more examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM