launchd interview questions
Top launchd frequently asked interview questions
I have a kext that I would like to be loaded at startup time. It doesn't need to be loaded particularly early in the process, but I would like it to be loaded before a user logs in.
The kext in question is InsomniaT, and, unlike a device driver, there is nothing that is automatically going to request that it be loaded into the kernel, so just putting it in /System/Library/Extensions won't do anything.
What's the best way to do this?
Source: (StackOverflow)
An app on a Mac that automatically launches on boot and I don't want it to. The app itself offers no way to prevent this. Rather than identify the app, I figured it would be nice to use this question as an opportunity to identify all the places such an app could hide.
Here's where I've looked so far, and I still haven't found it:
- Accounts - Login Items
- Dock - Open at Login
- launchd - Cycled through each tab of agents & daemons in Lingon
Other ideas?
Source: (StackOverflow)
I have the following launchctl command as a .plist file. It's loaded and set to run once a day but, it needs to run as root and I'm not sure how to verify this.
Also, this cron job basically CDs into a directory and runs a command. I'm sure launchd has a better way of specifying the directory where it's supposed to run the command.
How do I know it's run as root and is there a better way to write 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>dev.project.frontpage.feedparser</string>
<key>ProgramArguments</key>
<array>
<string>cd</string>
<string>/Users/eman/src/project/trunk/includes/;</string>
<string>./feed-parser.php</string>
<string>-c</string>
<string>./feed-parser-config.xml</string>
</array>
<key>QueueDirectories</key>
<array/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>WatchPaths</key>
<array/>
</dict>
</plist>
Source: (StackOverflow)
I have a launchd daemon placed in ~/Library/LaunchAgents
that worked well in Mavericks. But it won’t start in Yosemite public beta. The daemon plist is like this (my username is darksair
with UID 501)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.darksair.retrmail</string>
<key>ProgramArguments</key>
<array>
<string>/Users/darksair/bin/retrmail.py</string>
</array>
<key>KeepAlive</key>
<false/>
<key>StartInterval</key>
<integer>300</integer>
<key>LaunchOnlyOnce</key>
<false/>
<key>UserName</key>
<string>darksair</string>
<key>ProcessType</key>
<string>Standard</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/Users/darksair/Python/bin:/Users/darksair/Python3/bin:/Users/darksair/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardOutPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
<key>StandardErrorPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
</dict>
</plist>
Basically it is supposed to run ~/bin/retrmail.py
every 5 minutes.
I notice that in Yosemite launchd is upgraded to 2.0, and launchctl has new commands. I tried
sudo launchctl kickstart user/501/org.darksair.retrmail
and it said
Could not find service "org.darksair.retrmail" in domain for uid: 501
I also tried the old school
sudo launchctl load ~/Library/LaunchAgents/retrmail.plist
and it said
/Users/darksair/Library/LaunchAgents/retrmail.plist: Path had bad ownership/permissions
The file is owned by me and the staff group. I tried both permission 644 and 600 with the same error.
So does anyone know how to properly fire up a launchd daemon in Yosemite?
UPDATE: Looks like my launch agent file has to be owned by root:wheel
. After I chown, I tried
sudo launchctl load ~/Library/LaunchAgents/retrmail.plist
and it didn’t issue any error. And I think my deamon is running properly. I’ll leave this question open because I remember the launchd document clearly states that the launch agent file can be owned by the user running the daemon.
UPDATE2: No it wasn’t running properly. It got run only once, but not again, as if it was unloaded.
UPDATE3: I upgraded to Yosemite public beta 3, and changed my agent to this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.darksair.retrmail</string>
<key>ProgramArguments</key>
<array>
<string>/Users/darksair/bin/retrmail.py</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>UserName</key>
<string>darksair</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/Users/darksair/Python/bin:/Users/darksair/Python3/bin:/Users/darksair/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardOutPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
<key>StandardErrorPath</key>
<string>/Users/darksair/logs/retrmail.log</string>
</dict>
</plist>
I reloaded this agent, and I think now it is working properly. I’m still leaving this question open because I don’t know what’s wrong with my previous plist.
In conclusion, what I found is I have to change the owner of the plist to root:wheel
in order to load it.
Source: (StackOverflow)
I used Apple's seemingly straightforward docs to create a LaunchDaemon to run a Node.js script I wrote.
Here's the plist
file. It's basically exactly a copy-paste from Apple's docs, set to run every 300 seconds:
<?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.wintr.eodemail</string>
<key>ProgramArguments</key>
<array>
<string>~/projects/eod_email/eod</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>StandardOutPath</key>
<string>/var/log/eod-email.log</string>
<key>StandardErrorPath</key>
<string>/var/log/eod-email.log</string>
<key>Debug</key>
<true/>
</dict>
</plist>
Here's the error I get in /var/log/system.log
:
Jul 22 10:55:52 Nick-Cox com.apple.xpc.launchd[1] (com.wintr.eodemail[7097]): Service could not initialize: 14E46: xpcproxy + 13421 [1402][7D917364-B96E-3F93-B923-A89B5BF5736D]: 0x2
What I've done:
- It has the same permissions as the rest of the files in /Library/LaunchDaemons (
-rw-r--r--
, owned by root)
- I read the docs for xpc, but that didn't help much.
- I made sure that the Node.js script was adequately permissive (777), and runnable from the command line (it is).
- Tried the absolute path to the file (
/Users/nickcox/projects/eod_email/eod
) and made sure I ran launchctl unload (daemonname)
and launchctl load (daemon name)
This seems much more complicated than cron, which is apparently deprecated, according to those Apple docs. What do I need to do to get this script to run on a schedule?
Source: (StackOverflow)
I find my Mac's syslogd "Cosole" logs become unusable when some badly written app (PathFinder.app in this case) incessantly spews into syslogd all day long.. I read somewhere that you could disable logging PER app by..
Creating an alias to the executable bundle inside the App "package", and then ONLY launching that alias FROM the terminal. The process was... Browse to /Applications/ObnoxiousLogger.app, right click, "Show Package Contents", and then Browse to...
/Applications/ObnoxiousLogger.app/Contents/MacOS/ObnoxiousLogger
Then you make the alias through the GUI and remember to always launch the app from that alias, again ONLY via the terminal.
This is annoying, as you HAVE to create the alias via the Finder (symlinking doesn't work, and there is no way to create an alias via the terminal). And if it gets launched ANY other way, youre back to square one, logorrhea.. This method DID work, but for a very short amount of time.
It would seem you could set this via a launchctl command, or a plist variable, but this isn't an app that is opened by launchd, and launchd's documentation is so all-over the place, but I guess this is a possibility, I suppose.
I saw something about sending the log to /dev/null, but it wasn't clear if this was some kind of syslogd pipe, or command, or an /etc/syslogd.conf setting, or what...
Please let me know if you have a surefire way to selectively silence logging per application, or even better, increase or decrease the logging verbosity, per process / command, etc in Mac OS X.
Source: (StackOverflow)
I remember sometime ago, I uninstall an application called starfield, but probably I didn't do a clean uninstall. Now in Console, I always see a annoying message:
com.apple.launchd[1] (com.starfield.backupservice[4441]) Exited with exit code: 1
com.apple.launchd[1] (com.starfield.backupservice) Throttling respawn: Will start in 10 seconds
com.apple.launchd[1] (com.starfield.backupservice[4442])
posix_spawn("/Applications/Starfield/BackupService/offSyncService", ...): No such file or directory
I know it could be something wrong with my installation, how can I do a clean uninstall now, or just fix this issue, I don't want to see this message from my console any more.
Thanks.
Source: (StackOverflow)
I've been trying to up the maxfile limit and maxfileperproc limit on Yosemite, with no luck. I have created a sysctl.conf file in the etc folder, which has successfully increased the values when displayed via grep.
However, if I look at launchctl limit maxfiles, the value is is still incorrect.
Some solutions appear to be using ulimit -n to set the limit, but when in terminal, I cannot actually use this. It gives me an error of "Invalid argument" or "Unauthorized operation". I have successfully increased ulimit through a bash_profile script, but since the application is run from Applications, not the shell, it is irrelevant. I also successfully increased ulimit through the root user, but when that is logged out, it doesn't save changes.
Ideally, I'm looking for something that works like the launchd.conf file did, and just increases launchctl limit maxfiles {#} automatically on reboot.
Is there a way to do this successfully? Maybe using a 3rd party like Lingon, or with a launch daemon?
Thanks!
Source: (StackOverflow)
I tried to update Homebrew on time with launchd. My plist file is presented here:
<?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>ms.liu.homebrew.update</string>
<key>UserName</key>
<string>LiuMS</string>
<key>ProcessType</key>
<string>Background</string>
<key>EnvironmentVariables</key>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>update</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>20</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>/usr/local/logs/ms.liu.homebrew.update.out</string>
<key>StandardErrorPath</key>
<string>/usr/local/logs/ms.liu.homebrew.update.err</string>
</dict>
</plist>
It does work somehow: I can execute launchctl start ms.liu.homebrew.update
manually to update my Homebrew. However, launchd doesn't execute this service periodically: last changes to the file which stdout redirects to is two days ago.
I tried to get info about this service but got nothing:
> launchctl print user/%MyPID%/ms.liu.homebrew.update``
Could not find service "ms.liu.homebrew.update" in domain for uid: %MyPID%
It looks like I haven't successfully loaded my service. How? I used launchctl load
but it seems that it has been deprecated. Man page recommends bootstrap instead:
> launchctl bootstrap user/%MyPID% %Path-to-plist%
> %Path-to-plist%: Service cannot load in requested session
What should I do? How to properly use launchctl bootstrap
and launchctl print
?
I am running OS X Yosemite GM Candidate 1 on MacBookPro with Retina display (2013).
Source: (StackOverflow)
I’m unable to schedule a periodic launch with launchctl
/launchd
on OS X (Leopard). Basically, I’m unable to find a step-by-step list of instructions on the web and the intuitive approach doesn’t work.
The sync.plist
file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.madrat.utils.sync</string>
<key>Program</key>
<string>rsync</string>
<key>ProgramArguments</key>
<array>
<string>-ar</string>
<string>/path/to/folder/</string>
<string>/path/to/backup/</string>
</array>
<key>StartInterval</key>
<integer>7200</integer>
</dict>
</plist>
I’ve put this script inside the path ~/Library/LaunchAgents
.
Next, I’ve registered the script using
launchctl load ~/Library/LaunchAgents/sync.plist
Finally, to test that it works, I started the job:
launchctl start net.madrat.utils.sync
– Nothing happened. Manually executing the rsync
command in the terminal yields the expected result.
I’m fairly sure that the job was registered correctly because if I try to start a non-existing job, I get an error message (which I didn’t get in the above command).
What did I do wrong?
Source: (StackOverflow)
When I run Zotero/Firefox, they often crash and I am left with zombie processes; after this I cannot open new instances of Zotero or Firefox. I want to get rid of these zombie processes rather than rebooting, so for <pid>
of the zombie process,
$ ps -p <pid> -o ppid=
gives me the <parent_pid>
and
ps aux | awk -v PID=<parent_pid> '$2 == PID {print $0}'
tells me the parent process is /sbin/launchd
for user crippledlambda
.
Is there a way to restart this without killing my system?
sudo kill -1 <parent_pid>
does nothing. I've tried writing this in a script and running it with sudo
:
for i in `launchctl list | grep launchd | awk -v PID=<parent_pid> '$1==PID { print $NF }'`; do `launchctl stop $i && launchctl start $i` ; done
and this obviously(?) leaves me with an unresponsive gray screen so I have to reboot anyway. Thanks in advance for your suggestions.
Source: (StackOverflow)
I created a launchd .plist file to in order to have a python script run every hour. I ended up editing and later deleting the .plist file ( in /Library/LaunchDaemons )... but somehow launchd is still trying to run the script.. The file that the original .plist was calling is also no longer present ( it was in /usr/bin ).. Now every 10 seconds launchd is still attempting to run the script, fails, and respawns...
I tried fixing this with Lingon.... to no avail.. Is there a way to kill this process for good? I tried logging out and restarting as well...
Machine is running 10.5.8
Source: (StackOverflow)
I installed a program a few months ago, it had a startup option that I did install. Later, I decided to remove the program, but it seems to have left the startup script or item even after I uninstalled it.... and its trying to start every few seconds.
How can I remove this item?
Here is it from the console
$ com.apple.launchd[1] (com.jft.PdaNetMac[24476]): Exited with exit code: 1
$ com.apple.launchd[1] (com.jft.PdaNetMac): Throttling respawn: Will start in 10 second
Source: (StackOverflow)