The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Launching script on login (http://hintsforums.macworld.com/showthread.php?t=84127)

cwtnospam 01-10-2008 10:39 PM

Login Hook, launchd, it just doesn't seem to want to work. :confused:

I'm trying to automatically start Folding@home on login. So far, the only way I've been able to do it is using an Applescript.app and login items. I need a way to execute this line in a Terminal window:

/path/to/fah5 -local

If I try to execute it from a shell script, it doesn't run. If that shell script is a login hook, it hangs the system! From Applescript I can tell the Terminal to open a new window and execute fah5 in it, but I'd prefer to get a login hook or launchd to work. Any ideas?

- Oh, and this is in Tiger.

chabig 01-10-2008 11:36 PM

I used Lingon to create this LaunchAgent:

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>RunFolding</string>
        <key>ProgramArguments</key>
        <array>
                <string>/path/to/fah5</string>
                <string>-local</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>


cwtnospam 01-11-2008 12:11 AM

Close! But it doesn't get the -local portion correct. This gets logged repeatedly in the Console:

Quote:

[05:04:43] Configuring Folding@Home...

User Name? Team Number? Ask before fetching/sending work (no/yes) [no]? Use proxy (yes/no) [no]? Allow receipt of work assignments and return of work results greater than
5MB in size (such work units may have large memory demands) (no/yes) [no]? Change advanced options (yes/no) [no]? [05:04:43] Could not write MyFolding.html.
Maybe if I move the app to the same folder as the data...

Yes, moving the app seems to work, but since it's no longer running in a Terminal window, I can't be sure. Anyone know of a way to redirect the output of a running process? It appears to be writing these files:

/usr/lib/dyld
/usr/lib/libSystem.B.dylib
/dev/null
/dev/console

I'm assuming /dev/null would normally be the Terminal window.

tlarkin 01-11-2008 01:48 AM

Isn't folding@home an application, or is it strictly a background process?

So, maybe use loginwindow manager with this simple shell script, of course this will be at log in not start up, so you would have to log in.

Code:

#!/bin/bash

open -a "folding@home.app"


P6SMSKC 01-11-2008 05:26 AM

Quote:

Originally Posted by cwtnospam (Post 441278)
Anyone know of a way to redirect the output of a running process?

If your still launching the script with launchd you can direct the standard output and standard error paths. The pertinent part of the plist for changing standard out looks like this.
Code:

<key>StandardOutPath</key>
        <string>/Library/Logs/myscript/myscript.stdout</string>

I use lingon so I'm not sure that's the only required key to redirect output, but I think so. Lingon rocks btw.

cwtnospam 01-11-2008 08:59 AM

Quote:

Originally Posted by tlarkin (Post 441285)
Isn't folding@home an application, or is it strictly a background process?

Fah is a small (256K) Unix executable that calls FahCore_78.exe which is (2.6 MB), so I'm not sure what's going on there.

Quote:

Originally Posted by P6SMSKC (Post 441308)
The pertinent part of the plist for changing standard out looks like this.
Code:

<key>StandardOutPath</key>
        <string>/Library/Logs/myscript/myscript.stdout</string>


That did it!

Hal Itosis 01-11-2008 07:06 PM

Quote:

Originally Posted by tlarkin (Post 441285)
Isn't folding@home an application, or is it strictly a background process?

So, maybe use loginwindow manager with this simple shell script, of course this will be at log in not start up, so you would have to log in.

Code:

#!/bin/bash

open -a "folding@home.app"


I'm just adding some general info, not suggesting a solution here.
To fire up an "app" via launchd plist, here is another way (I use):
Code:


        <key>ProgramArguments</key>
        <array>
                <string>/Applications/FastScripts.app/Contents/MacOS/FastScripts</string>
        </array>


cwtnospam 01-12-2008 09:13 AM

Well, I thought it was working. :(
For some reason, FAH is failing in the middle of work units:
I noticed this at the top of the output file: Ignoring argument: -local

when I run it from the Terminal, I get: Using local directory for work files

Here's a sample error:
Code:

[18:39:32] Writing local files
[18:39:32] Writing local files
[18:39:32] Completed 0 out of 5000000 steps  (0)
[20:28:44] Writing local files
[20:28:45] Completed 50000 out of 5000000 steps  (1)
[22:09:22] Writing local files
[22:09:22] Completed 100000 out of 5000000 steps  (2)
[23:53:27] Writing local files
[23:53:27] Completed 150000 out of 5000000 steps  (3)
[23:53:27] Size of work/wudata_03.xtc not what saved.
[23:53:27]
[23:53:27] Folding@home Core Shutdown: FILE_IO_ERROR
[23:53:28] CoreStatus = 75 (117)
[23:53:28] Error opening or reading from a file.
[23:53:28] Deleting current work unit & continuing...
[23:53:28] - Preparing to get new work unit...

I'm running it in the Terminal now to see if that still works, but it's only at step 17 out of 100.

P6SMSKC 01-12-2008 05:52 PM

Quote:

Originally Posted by cwtnospam (Post 441610)
I noticed this at the top of the output file: Ignoring argument: -local

when I run it from the Terminal, I get: Using local directory for work files

What type of agent / daemon are you calling fah from...i.e. where is the plist. Processes started from /Library/LaunchAgents or /Library/LaunchDaemons will be run as root and have no HOME defined (I think) and lack permissions to be in your home anyway. I've had this trouble before with processes launched by anacron.

Try writing a script that will launch FAH for you. and then just calling that script from launchd. Have the script export HOME as your users home directory. I know there are provisions for defining the home directory within a launchd plist, but I've not used them so I don't know if this will help.

OTOH if you have the plist in ~/Library/LaunchAgents I've got no idea. Does FAH have any way to pass more info to it on launch (--path-to-workspace="")?


p.s. do any of you have trouble hitting tab to auto-complete only to realize your in a text editor?...I do this all the time.

cwtnospam 01-12-2008 06:54 PM

The plist is in ~/Library/LaunchAgents. I tried to do this through a script, but I don't know of another way to run it from a Terminal window without using osacript, in which case I might as well call it from login items.

tw 01-13-2008 03:27 PM

Quote:

Originally Posted by cwtnospam (Post 441701)
The plist is in ~/Library/LaunchAgents. I tried to do this through a script, but I don't know of another way to run it from a Terminal window without using osacript, in which case I might as well call it from login items.

try saving it in /Library/LaunchAgents rather than ~/Library/LaunchAgents - that will run it as root and avoid any permissions problems. you might need to explicitly set the working directory using the 'WorkingDirectory' key - it's not clear from the posts so far precisely where the files it's working with live.

cwtnospam 01-13-2008 04:06 PM

Won't that cause it to run for each user that logs in? If I give it explicit paths in that case, they couldn't be in a user's home, but if they weren't, then I could end up with multiple instances working on the same data.

Maybe I'll try it between snow shoveling sessions tomorrow. :eek:

tw 01-13-2008 04:58 PM

well, the other alternative is to launch it from the root folder, but use the UserName key to make sure it always runs as a particular user (I'm assuming they have that key in Tiger, incidentally - I only have easy access to the Leopard man page). that might mean that you'd want create a separate user dedicated to doing whatever it is this app does...

I checked out the folding@home website, incidentally. you know, on the FAQ page they imply you can just add folding@home to your login items, and it will run just fine. see it here... did you try that way, and if so what was the problem?

cwtnospam 01-13-2008 05:05 PM

That's the graphical application. I'm using the command line console in this case so that it runs in the background while I use the system. I also run the screen saver, so that gives me two instances at a time. Since I've only got a dual processor system, that's all I want running.

cwtnospam 01-13-2008 05:11 PM

Here's the Applescript I was using to start it. I saved it as a run only app and added it to login items, and it works well, except that I can't do anything until after the gui scripting completes. A login hook or launchd wouldn't need the gui portion and it would be quicker too.

Code:

tell application "Terminal"
        activate
        tell application "System Events"
                key down command
                keystroke "n"
                key up command
        end tell
        set pth to "/Users/username/Documents/fah5 -local"
        do script pth in window 1
end tell


tw 01-13-2008 05:21 PM

well, the Console version has the same instructions (here). my sense is, though, that this opens and runs the command in terminal. let me try downloading it myself and see what happens...

cwtnospam 01-13-2008 05:44 PM

Quote:

Originally Posted by tw (Post 441887)
well, the Console version has the same instructions (here).

So it does! Not only that, but it works, too!

tw 01-13-2008 05:57 PM

Quote:

Originally Posted by cwtnospam (Post 441890)
So it does! Not only that, but it works, too!

lol - well that makes things a trifle easier. :D

I actually wouldn't mind doing this myself, but man is it a CPU hog. does that settle down after a while?

cwtnospam 01-13-2008 06:00 PM

It's low priority, so it gets out of the way easily, but it will use as much of the cpu as is available. That's what I like about it. I can leave it running all the time, and it won't hog the processor when I need it. When I leave the computer, I start the screen saver, which keeps the other processor busy. That way my system is doing some good while I'm not using it.

tw 01-13-2008 06:11 PM

cool. I will run it then. :)


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