Launchd Starting LaunchAgents as a specific user.

Greetings.... I've gotten into the practice of using LaunchD and plists to create launch items, but I am having a unique issue I am hoping we can resolve.

I have a couple of launch items that I need to show up in root's launchd list because I have them run as other users on startup. For example, I have a user called "backups" that uses rsync to pull information form some servers I manage out in the world. Because of how I have set up permissions, I need it to run as that user. However, when I log in, it shows up in MY list of jobs.

This fails because even though I am an administrator, it appears that I do not have the capability (I'm a unix guy, so this makes sense to me) to reset a job as a user.

It is easily remedied after boot by unloading it from my queue, and loading it into root's queue.

The files are located in /Library/LaunchAgents, and are owned by root.

Anyone have a suggestion to fix this?

Mac Pro (2008), Mac OS X (10.5.2)

Posted on Mar 18, 2008 10:14 AM

Reply
11 replies

Mar 19, 2008 9:03 AM in response to Branden Williams

The apple website at http://developer.apple.com/macosx/launchd.html has a good intro to launchd, and some googling turned up info on specific parameters I needed to modify the cron example to do my bidding (the Weekday and Day keys under StartCalendarInterval). That is pretty much where my research ended.

That said, I understood that the user of whatever was run by launchd was determined by the location of the .plist file - /Library/LaunchDaemons, LaunchAgents = root, /User/username/Library/LaunchDaemon, LaunchAgent = user.

Why do you say launchd or launchctl is loading jobs for "backups" when you log in as "you"? This doesn't make sense on two fronts: the use of the "backups" user and the loading of anything when you log in. I would think only your local .plist jobs would be loaded.

The blind has spoken! -LS

Mar 19, 2008 9:08 AM in response to Branden Williams

Branden Williams wrote:
I actually used Lingon to create the plist files 🙂 But for whatever reason, it is running these under my launchctl queue, not root's.

IIRC, Lingon (which I tried initially, but the .plist files didn't work due to my use of command-line parameters, so I had to figure out how to roll my own) puts the scripts only in the root or local user directories. Did you do this as "backups" or while logged in as yourself? Maybe check the /Users/you/Library/LaunchDaemons directory? -LS

Mar 19, 2008 9:14 AM in response to LordSmoke

Ahh, so here's some fun. The scripts are owned by root, and are in /Library/LaunchAgents. But then run as ME when I log in.

Think of the backups user as just a background "service account." So I could have it run under that user specifically, not a problem, but I would never log into the machine under that user, so I need it to run at startup without logging in.

Maybe /Users/backups/Library/LaunchDaemons?

Mar 19, 2008 9:32 AM in response to Branden Williams

Branden Williams wrote:

Maybe /Users/backups/Library/LaunchDaemons?

Yes, see my first reply.

I can't recall the difference just now of LaunchAgents vs. LaunchDaemons. The apple link may discuss this.

Also, ownership of the file might matter, but I don't know. All of my run-as-root files are in /Library/LaunchDaemons and are owned by "root" with group "wheel". Maybe yours should be owned by "backups".

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Launchd Starting LaunchAgents as a specific user.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.