Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 01-15-2009, 05:57 PM   #1
jweinberger
Prospect
 
Join Date: Jan 2005
Posts: 11
Exclamation Can't stop launchagent

Hi:

I would very much appreciate any help anyone can offer on this issue - I am at a loss.

I successfully configured a launchagent (.plist) to run a script I wanted run every hour. I loaded it using launchctl load .....plist and it ran just fine - every hour as expected.

Then I needed to make some changes, and for unrelated reasons, needed to restart my mac. So I launchctl unload-ed the plist and it stopped running. I made the changes, restarted the mac, and my problems began.

The script was now (without my launchctl load-ing it) running every hour. I'd expect that since it was in the /system/library/launchagents directory, it would be started on system start-up.

But it has an odd problem - it is now running as an unpriveledged user, not as root (as it had been) and this needs to run as root (please, I know the security issues....).

So I tried to launchctl unload it. It told me it couldn't because it wasn't loaded. Yet it continues to run. I tried to launchctl load it then unload it. That produced no errors, but still the script runs. I also tried launchctl stop a few times. to no avail. And the .plist name does not appear at all in launchctl list.

I want to stop the script from running. is there any way to do this? Where might I find what's causing it to continue to run?

Any help is appreciated!!

FYI: Mac Mini, Intel Core Duo. Please let me know what further information might help diagnose this.

Thank you!
jweinberger is offline   Reply With Quote
Old 01-15-2009, 06:24 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
1) You should try restarting your Mac - you don't mention having done this after the problems started.

2) You shouldn't be putting things under /System - that is for Apple's use. Your system-wide launchd plists should go under /Library/LaunchAgents or /Library/LaunchDaemons.

3) If you want this script to run as root, then I think it should be a LaunchDaemon, not a LaunchAgent - what does this script do anyway? See: http://developer.apple.com/technotes...html#SECAGENTS
__________________
hayne.net/macosx.html

Last edited by hayne; 01-15-2009 at 06:27 PM.
hayne is offline   Reply With Quote
Old 01-15-2009, 07:03 PM   #3
jweinberger
Prospect
 
Join Date: Jan 2005
Posts: 11
in response:

1) I did. that's what caused the problem. Sorry I didn't say so, but I did again, and the same result - problem recurred.

2) that depends on what you're doing and how well you know what you're doing. Warning well heeded.

3) LaunchDaemons are just that - Daemons. They are programs that run continuously in the background waiting to be called (httpd is a good example - it's the webserver daemon that listens for requests on port 80 and hands them to a child httpd - server - process to handle).

Launchagents are also used for programs that run periodically (every minute, hour, day, etc.) This is essentially a cron replacement. So when you need to have something launched efery so often (the script that rotates the log files every night is an example), you use a launchagent.

Thanks for the reference doc. Its interesting and useful, but I can't find a pointer to a solution to this issue there.

in any case - the effect I need to end up with is to run the script at set intervals. LaunchAgents are the documented way to do this (and preferred over cron) in 10.5 (I'm running (10.5.6). I have a number of other such tasks that al work perfectly - it's just this one that's gone rogue.

So, my question remains:

most importantly: How do I stop this from running? restarting doesn't help and isn't practical as this is on my server.

Also very helpful: why is it running as an unpriviledged user after re-start - none of my other scripts are. Not sure why this one does.

Thank you!
jweinberger is offline   Reply With Quote
Old 01-15-2009, 07:13 PM   #4
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
Quote:
Originally Posted by jweinberger
that depends on what you're doing and how well you know what you're doing. Warning well heeded.

There is no reason that I can see to put things under /System.
What is the advantage compared to having them in the correct place (under /Library) ?

Quote:
LaunchDaemons are just that - Daemons. They are programs that run continuously in the background waiting to be called (httpd is a good example - it's the webserver daemon that listens for requests on port 80 and hands them to a child httpd - server - process to handle).

Launchagents are also used for programs that run periodically (every minute, hour, day, etc.) This is essentially a cron replacement. So when you need to have something launched efery so often (the script that rotates the log files every night is an example), you use a launchagent.

I think you need to read more about this - you seem to have a misunderstanding of the difference between an agent and a daemon.
From the Apple doc I linked to:
Quote:
Originally Posted by above Apple TechNote
The difference between an agent and a daemon is that an agent can display GUI if it wants to, while a daemon can't. The difference between an agent and a regular application is that an agent typically displays no GUI (or a very limited GUI).

Quote:
How do I stop this from running? restarting doesn't help and isn't practical as this is on my server.

You need to find out what plist is starting it. Look in all the approved locations for launchd items. And check if you have some other item or script that starts it up.
Maybe the 3rd-party utility "Lingon" would be of help in examing what launchd items are active.

Quote:
why is it running as an unpriviledged user after re-start - none of my other scripts are.

See table #2 of the above TechNote
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-15-2009, 08:00 PM   #5
jweinberger
Prospect
 
Join Date: Jan 2005
Posts: 11
Quote:
You need to find out what plist is starting it. Look in all the approved locations for launchd items. And check if you have some other item or script that starts it up.

I've searched in every way I know how (I tend to rely on using find / -iname "...*") and the only place I can find that would launch this is from the plist I mentioned. Nothing else I've created starts it.

I may not know of every place I could look, so I am hoping that someone here might suggest why this might happen or where I can look to see why. Any help is appreciated.

Quote:
See table #2 of the above TechNote

I read it carefully before responding. It does a nice job of explaining this, but has no relevance to the question as far as I can tell. The script and plist were both created by root. The plist was loaded as root.

After restart, it's utterly unclear to me how the plist could create a situation where it could run as anything but root, or why it has chosen to run as the specific unpriveledged user that it chose (not me, not root, some random other user).

This is all good information and helps me understand some details I did not before, but it does not get me any closer to figuring out how to stop the script from running.

There are lots of other interesting questions that you raise, and I'd love to hear how you might have done this, but I need to get this script to stop.

Can you (or anyone) suggest where I might look or how I might find out how to stop this?

Thank you.
jweinberger is offline   Reply With Quote
Old 01-15-2009, 09:26 PM   #6
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
I already recommended using "Lingon" to see what launchd items are active.

You can also do 'launchtl list' as a starting point towards seeing what items are installed.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-15-2009, 09:35 PM   #7
jweinberger
Prospect
 
Join Date: Jan 2005
Posts: 11
Quote:
I already recommended using "Lingon" to see what launchd items are active.

Yes, I saw that. I use Lingon - that's how I create and edit plists when I need to.

I'm not sure I understand, though, Lingon will show the list of what plist files are in the diectories, but I can't see how it looks at launchd and determines what's loaded and what's not - can it do that? if so, how?

Quote:
You can also do 'launchtl list' as a starting point towards seeing what items are installed.

As I noted in my original post:
Quote:
And the .plist name does not appear at all in launchctl list

So when I look at 'launchctl list' this item does not appear at all. Yet according the system log, launchd is running it.

That's why I'm at a loss to find out how it's getting launched which I think is pre-requisite to stopping it.

Any suggestions?
jweinberger is offline   Reply With Quote
Old 01-16-2009, 10:03 AM   #8
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
Note that 'launchctl list' does not show the plist file names - it shows the identifiers for the launchd items (which are inside the plist files).
So maybe your errant item is called something else (that you don't recognize in the list)
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-16-2009, 10:24 AM   #9
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
You can unload it from the command line

Code:
launchctl unload <name_of_agent.plist>
__________________
sudo make me a sammich
tlarkin is offline   Reply With Quote
Old 01-16-2009, 11:23 AM   #10
jweinberger
Prospect
 
Join Date: Jan 2005
Posts: 11
Re: hayne:

Quote:
So maybe your errant item is called something else (that you don't recognize in the list)

I searched the launchctl list output for anything that might be recognizable as the launchd items (yes, I am looking for the launchd item, not the plist, of course). I searched manually and using various tools like grep to filter for small parts of the launchd item name with no luck.

Is there another way to identify it in the launchctl list if what shows up there is completely unrelated to the name of the launchd item?

Also, you mentioned using Lingon to tell what items are active. It shows clearly what items are in the relevant directories, but I can't tell howto use it to show items that are loaded - can you tell me how?

Thanks

Re: tlarkin

Quote:
You can unload it from the command line

Thanks...but as I mentioned in my initial post, I tried that unsuccessfully in various ways. It doesn't stop.
jweinberger is offline   Reply With Quote
Old 01-16-2009, 12:00 PM   #11
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,352
are you sure its running then?
__________________
sudo make me a sammich
tlarkin is offline   Reply With Quote
Old 01-16-2009, 12:25 PM   #12
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
Let's get back to basics.
What is the name of the script that is running?
How do you know it is running? (presumably you see it in Activity Monitor)
What is the parent process (as seen in Activity Monitor when you set it to show all processes in hierarchical mode)?

If you kill that script, does it restart on its own? (after some time? only when you restart the Mac? only when you log out and log in again? when?)

Do you have any Login Items (in your Accounts preferences) that might be starting this script?
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-17-2009, 09:39 PM   #13
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
look, as Hayne said, if you put it in /System/Library/LaunchAgents it will be treated as though it's a core process, and you won't be able to get a lot of control over it even from an administrator account. you'd really best put it in /Library/LaunchDaemons, unless you have a very good reason for not wanting to do that. otherwise you're just making headaches for yourself.

the three ways to stop the process running are:
  • remove the plist and restart the machine
  • add a boolean key called Disabled and set it to true, then restart the machine
  • use launchctl - launchctl remove job-label

you should also check that you haven't accidentally made a copy of the plist under a different name (launchd gets the job name from the key inside the plist, so if you accidentally hit command-D and duplicate the file, or somesuch, you'll have issues)

as to why it's not running as root... interesting. I know that there are launchd keys that control which user a job is supposed to run under, and I think that the location and ownership of the script being run makes a difference (e.g. if the script lives in your user home folder and is owned by your user, launchd may run it as your user rather than as root). did you, perchance copy one of the plist files already in the launchagents folder and modify it? that has the potential (a) for having excess keys, and (b) for having accidentally saved it in the wrong plist file.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 01-18-2009, 10:29 AM   #14
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
If only you would:
• post the plist
• post a Terminal listing of it: ls -l /path/to/plist (so we can see location and perms)
a whole lot of time would be saved, and guesswork (or "20 questions") avoided.

-HI-
Hal Itosis is offline   Reply With Quote
Old 01-18-2009, 01:49 PM   #15
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
jweinberger's first order of business the last time we heard from him/her was to find out what is starting the script that is currently running, not to figure out what is wrong with the plist - that is now a secondary thing.

I'm waiting for the answers to my questions of post #12
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-18-2009, 03:33 PM   #16
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by hayne
jweinberger's first order of business the last time we heard from him/her was to find out what is starting the script that is currently running, not to figure out what is wrong with the plist - that is now a secondary thing. I'm waiting for the answers to my questions of post #12

That's odd... the word >sudo< doesn't even appear in any of the discussion above, yet this plist is located in the /System folder?!?! Or are we to assume all Terminal commands provided above were (or should be) issued in a root shell? There's a whole lot of vital detail missing i'd say.

Last edited by Hal Itosis; 01-18-2009 at 03:37 PM.
Hal Itosis is offline   Reply With Quote
Reply

Tags
agent, launchagent, launchctl, launchd

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 04:40 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.