The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   System (http://hintsforums.macworld.com/forumdisplay.php?f=4)
-   -   LaunchDaemon to run at every logon? (http://hintsforums.macworld.com/showthread.php?t=95586)

kaptagat 11-05-2008 06:15 AM

LaunchDaemon to run at every logon?
 
Hello Everyone

Our marketing staff sometimes have to "hotdesk" between their Macs so they have been told to save everything in the /Users/Shared folder and I have got a simple script (chmod -R 777 /Users/Shared) that is run by Mike Bombich's login window manager so that when someone logs on, it ensures they can work on all the files in that folder. This is working fine but I have been experimenting with using a launchdaemon (written with lingon) but it only runs when the system is restarted. Does anyone know how to make it run when a user logs on? The option to run it when the folder is modified works, but I don't want it running all the time.

thanks

fracai 11-05-2008 10:14 AM

Not sure about running at login, but you could check out the WatchPaths key.
man launchd.plist

See also this discussion.

agentx 11-05-2008 11:55 AM

Lingon is a GUI to launchd it will help you out

get the right version for your OS..

oops ignore me.......you are using Lingon...
Should be a User Agent (launched when anyone logs in) then Run it when loaded by System or Login should be checked.

kaptagat 11-05-2008 12:03 PM

agentx

I use Lingon and the option to "runatload". The blurb on this option says to use this if you want it to run at system startup or login, but in practice it only runs on startup.

tw 11-05-2008 11:25 PM

Quote:

Originally Posted by kaptagat (Post 501719)
agentx

I use Lingon and the option to "runatload". The blurb on this option says to use this if you want it to run at system startup or login, but in practice it only runs on startup.

it will run at startup if you save it in /Library/LaunchAgents or /Library/LaunchDaemons. to have it run at login, save it in ~/Library/LaunchAgents. this means you'll have to put a copy (or at least an alias) in each user's folder, though.

tlarkin 11-05-2008 11:47 PM

I believe launchagents is a log in hook, and runs when any user logs in (or specific if it is in the home folder) and LaunchDaemons is a system daemon and just plain runs at boot up. That is the minor difference.

kaptagat 11-06-2008 06:22 AM

Putting a copy in every user's folder is not practical and I have tried putting it the /Library/LaunchAgents folder where it does run at every logon, but not as root, as the following entries in the system.log show :-

Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aaa.rtf: Operation not permitted
Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aab.rtf: Operation not permitted
Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aac.rtf: Operation not permitted
Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aad.rtf: Operation not permitted

tlarkin 11-06-2008 09:36 AM

make sure it is owned by root:wheel

then once it is in place use launch control, launchctl list, to see current launch items running, and you can use launchctl to also manually start your daemon, via the launchctl launch command I believe.

Also, it looks like you are trying to run a rich text file. If you are running a script you need to save it as plain text, with the sh extension. I am betting you created it in textedit which by default, always saves items in rich text format.

Oh wait, not enough coffee yet, you are running to run the chmod command on those rtf files....and it doesn't have proper permisisons.

Can I see your script please?

kaptagat 11-06-2008 10:20 AM

The plist is owned by root. The rtf files are simply test files (chmod 755) in the shared folder. The system.log entries shows that plist is running correctly when a user logs on, but is unable to "chmod" the files to 777 which indicates it is not running as root.

tlarkin 11-06-2008 10:20 AM

Quote:

Originally Posted by kaptagat (Post 501890)
The plist is owned by root. The rtf files are simply test files (chmod 755) in the shared folder. The system.log entries shows that plist is running correctly when a user logs on, but is unable to "chmod" the files to 777 which indicates it is not running as root.

OK, can you post a ls -al of your plist and can you please post your script?

kaptagat 11-06-2008 10:32 AM

here is the plist :-

<?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>chmod_777</string>
<key>ProgramArguments</key>
<array>
<string>chmod</string>
<string>-R</string>
<string>777</string>
<string>/Users/Shared/</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

tlarkin 11-06-2008 11:25 AM

try putting the full path of chmod.../bin/chmod and see what happens

kaptagat 11-06-2008 11:54 AM

Still the same I'm afraid. Same entries in the system.log

tlarkin 11-06-2008 12:19 PM

I wonder why that is. Have you tried making an actual shell script and then putting that script on the machines locally, then having your launchd item just run the script?

tw 11-06-2008 07:14 PM

maybe what you need is a different approach. rather than trying to check for when users log in, why not just make a watchfolders plist that will modify files as soon as they are dropped in the folder. like follows:
Code:

<?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>chmod_777</string>
        <key>ProgramArguments</key>
        <array>
                <string>chmod</string>
                <string>-R</string>
                <string>777</string>
                <string>/Users/Shared/</string>
        </array>
        <key>WatchPaths</key>
        <array>
                <string>/Users/Shared</string>
        </array>
</dict>
</plist>

this way the permissions are immediately changed, and whenever someone logs in the file will be available.

kaptagat 11-07-2008 05:59 AM

Quote:

Originally Posted by tlarkin (Post 501906)
I wonder why that is. Have you tried making an actual shell script and then putting that script on the machines locally, then having your launchd item just run the script?

Still the same. It is beginning to look like that user agents don't run as root.

Thanks TW, I had previously tried that option and it does work but I didn't really want something running all the time however it looks like I will have to go with that option and run it as a launchdaemon. Shame that Mike Bombich has stopped developing his loginwindowmanager because I found it a very useful piece of software.

tlarkin 11-07-2008 09:49 AM

hmm, that is very strange. Last year in our 1:1 deployment I had a log in hook that ran at log in, and it would simply force a reconnect to our preferred network (airport) and make sure that the airport was turned on and active.

I tossed the script in /usr/sbin, made it executable and owned by root. Then I had a launchd item in /Library/LaunchAgents and every time a user would log in, it would simply trigger the script in the local path of /usr/sbin/airport.sh

It worked. That was on a Tiger image too.

Very strange.

Another option would be to have the launchd item watch the shared folder, and every time it is modified apply the new permissions.

kaptagat 11-07-2008 09:56 AM

But did it need take root authentication to carry out your task?

tlarkin 11-07-2008 09:57 AM

Quote:

Originally Posted by kaptagat (Post 502033)
But did it need take root authentication to carry out your task?

Yes, because some of the network changes require admin rights

biovizier 11-07-2008 10:18 AM

If it needs to run as "root" at each login, why not go with an old fashioned (in OS X terms) login hook?
http://support.apple.com/kb/HT2420


All times are GMT -5. The time now is 10:20 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.