Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > Team MacNN > FAH auto startup using crontab

FAH auto startup using crontab
Thread Tools
d0ubled0wn
Grizzled Veteran
Join Date: May 2002
Location: Michigan, USA
Status: Offline
Reply With Quote
Jan 17, 2004, 11:54 PM
 
I'm hoping someone can verify that my cron startup will work (I'd rather not reboot right now to find out.) Here's my setup,

I created two directories ~/Applications/fold1 and ~/Applications/fold2

My script foldit in each directory:
#!/bin/sh
./fah4 -advmethods -local -forceasm >/dev/null &
Finally, my crontab:
@reboot /Users/dave/Applications/fold1/foldit;/Users/dave/Applications/fold2/foldit
So, will this work?

I also want to know if there is recommended way to quit the client before rebooting. Will I lose progress on my current WU if I reboot without quitting the client? I'm guessing I'll just lose progress on the current frame it's working on.

Thanks.
     
reader50
Administrator
Join Date: Jun 2000
Location: California
Status: Offline
Reply With Quote
Jan 18, 2004, 12:14 AM
 
It might work. This is how I would do it:
Code:
@reboot cd /Users/dave/Applications/fold1; ./foldit & @reboot cd /Users/dave/Applications/fold2; ./foldit &
Changes:
Broke the two launch commands onto two lines.
Added the 'cd' to set the default directory for the script before launching.
Added a space after the semicolon to help separate the statements. Probably not needed.
Added the period '.' before the launch command so the crontab will know what it's supposed to do.
Added the '&' flag so the scripts would not die if cron were killed or died. Yes, it's very unlikely for cron to go down, but it's possible.

Note, on HFS/HFS+, case is unimportant. You could have done the crontab in all lowercase or ALL UPPERCASE and it would still work.

Rebooting while the script is running will normally cost you any work done on the current frame. The exception is if you quit while the client is writing to disk, I'm not sure what happens then. It would be nice if the client is smart enough to recognize a system shutdown, and complete the write-to-disk before quitting.
( Last edited by reader50; Jan 18, 2004 at 12:37 AM. )
     
Welnic
Forum Regular
Join Date: Nov 2002
Location: Santa Barbara CA
Status: Offline
Reply With Quote
Jan 18, 2004, 01:58 AM
 
My crontab looks like the one that Reader 50 suggests. The client seems to shut down correctly during a reboot. It writes:

Folding@home Client Shutdown.

to FAHlog.txt when it gets shutdown during a reboot, since it has time to do that it should be able to finish writing to disk if it was in the middle of it. You do lose the work that was done since the last frame.
     
mikkyo
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status: Offline
Reply With Quote
Jan 19, 2004, 06:24 AM
 
mine looks like
Code:
@reboot /Users/mikkyo/startfolding 0,15,30,45 cp /Applications/Folding/unitinfo.txt /Users/mikkyo/Sites/;cp /Applications/Folding2/unitinfo.txt /Users/mikkyo/Sites/unitinfo2.txt
The copies of the unitinfo files are for the cool php monitor script to access.
See here
http://forums.macnn.com/showthread.p...ht=php+monitor

startfolding looks like
Code:
#!/bin/sh cd /Applications/Folding /usr/bin/nohup /usr/bin/nice -n -20 ./fah4 -local -advmethods -forceasm >/dev/null & #prevent accidently running the same client twice cd ../ cd /Applications/Folding2 /usr/bin/nohup /usr/bin/nice -n -20 ./fah4 -local -advmethods -forceasm >/dev/null &
     
d0ubled0wn  (op)
Grizzled Veteran
Join Date: May 2002
Location: Michigan, USA
Status: Offline
Reply With Quote
Jan 19, 2004, 06:10 PM
 
Thanks all, I think I got it set now. Maybe someday I'll learn what all that **** actually means.
     
mikkyo
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status: Offline
Reply With Quote
Jan 19, 2004, 08:55 PM
 
For the startfolding script:
cd means Change Directory
so cd /Applications/Folding
is like opening the Applications folder and then Folding folder in the Finder.

/usr/bin/nohup (no hangup) is a program that prevents hanging up on the program you execute with it.
When you are logged in, you can launch programs, and when you log out, they quit.
A similar thing occurs in the Terminal.
When you launch Terminal you logon to a tty, the text interface you are using in the Terminal window. If you were to launch something in that window via the command line, and then close the window, the program would quit, because closing the window is like logging off of the tty.
So you use nohup to tell the OS that you are launching a program, that you want to not go away when you close the window or quit Terminal.

/usr/bin/nice is a program that sets the amount of processing power you want a program to use. For any program you launch normally, the default is 0, which is the "normal" amount. A value of 20 is super nice, in that the program will give up as much CPU time as possible to other applications or the OS. An amount of -20 is super unfriendly and says to give that program as much CPU power as possible, usurping other apps with lower priorities. So if you want to dedicate a machine to crunching, you can set its nice value to -20.

The flags for folding @ home have been pretty much explained.

The "> /dev/null" says to redirect(>) all the output that would normally show up in the Terminal window to the null device (/dev/null) which means nowhere. In other words, ignore all output from the program.

The & symbol means to put the program into the background and run it behind the scenes, basically getting it out of the users way.
If you want something to run all the time, and you don't need to interact with it, you can stick it in the background. A distributed computing client is a great example.

Hope that helps.
     
SciFrog
Dedicated MacNNer
Join Date: Jun 2003
Location: NY
Status: Offline
Reply With Quote
Jan 19, 2004, 09:45 PM
 
Aren't nohup and & redundant?
     
Welnic
Forum Regular
Join Date: Nov 2002
Location: Santa Barbara CA
Status: Offline
Reply With Quote
Jan 20, 2004, 12:39 AM
 
They are actually different. The & just makes the process run in the background. There is no guarantee that when you close that terminal window the process won't quit. When I was testing that the other day it seemed that as long as I typed exit to close the terminal window then the process kept running, but if I just closed the window it killed the process.

A couple of my linux boxen are the same way, but some are not. Some if you exit all processes that you started quit, others the processes keep running. So now whenever I want something to keep running I start it using nohup. I didn't feel that it was that important just using OSX, but it seems like a good habit to get into.
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jul 16, 2004, 11:30 AM
 
Interesting, this thread is exactly what I was looking for. I had not minded manually logging into my 6 - 8 machines and turning folding on when I was aware of reboots or crashes, but now I think it's time to move to cron. I wasn't aware of the @reboot stuff, I thought I was going to have to learn some cron time notation stuff and write a script to check if folding was already running, etc... I augmented the various cron lines in this thread and came out with mine below:
Code:
@reboot cd /Users/aorth/; /usr/bin/nohup /usr/bin/nice -n -20 /usr/bin/screen ./fah4 -advmethods -forceasm >/dev/null &
I throw my FAH session into a screen so I can play with it later. I can log into the box from home and reattach to the process to check status or to quit it nicely. (screen -r works well for attaching, then control-A-D will detach again). Thanks for the pointers on the cron, I'm glad I found this thread.

Long live team MacNN.

edit: Oops, I messed up that crontab. I didn't realize that cron could only one command.. I tried putting all my commands in a script and then having cron run that script but no go. I'll play with it later. Bah, manual start it is.
( Last edited by [APi]TheMan; Jul 16, 2004 at 11:44 PM. )
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Welnic
Forum Regular
Join Date: Nov 2002
Location: Santa Barbara CA
Status: Offline
Reply With Quote
Jul 16, 2004, 04:17 PM
 
I don't see anything in your crontab that would not run. You can call more than one command on a line. I have the following line in my crontab (now commented out) from when I ran chessbrain, and it didn't have any trouble running:

@reboot cd ~/chess;nohup nice -n 15 ./cbspn >output.txt &

The thing that looks suspicious with your crontab is the directory that you cd into. Do you really have F@H running loose in your home directory?

For monitoring F@H I run:
tail -f FAHlog.txt
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jul 16, 2004, 11:47 PM
 
Originally posted by Welnic:
I don't see anything in your crontab that would not run. You can call more than one command on a line. I have the following line in my crontab (now commented out) from when I ran chessbrain, and it didn't have any trouble running:

@reboot cd ~/chess;nohup nice -n 15 ./cbspn >output.txt &

The thing that looks suspicious with your crontab is the directory that you cd into. Do you really have F@H running loose in your home directory?

For monitoring F@H I run:
tail -f FAHlog.txt
Yeah, I really do have f@h running loose in my home directory. I don't use the -local flag, though, so it's not running too loosely. I guess I copied the wrong command when I was writing the above post... yeah, I screwed that post up bigtime.

Those commands run fine when I run them manually but restarts don't have them run. crontabs get run as root, right?
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
mikkyo
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status: Offline
Reply With Quote
Jul 17, 2004, 12:18 AM
 
crontab runs its commands as the user that entered the crontab.
So if you were root when you added the cronjob or did sudo crontab cronfile, it will run as root.
If you were just logged in as yourself, it runs as though you ran the command.
You shouldn't use ~ for home in crontabs as an absolute path is better and reduces the chance of failure.
so
cd /Users/you/chess; /usr/bin/nice -n 15 ./cbspn >output.txt &
Using that example is better.
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jul 17, 2004, 02:35 PM
 
Originally posted by mikkyo:
crontab runs its commands as the user that entered the crontab.
So if you were root when you added the cronjob or did sudo crontab cronfile, it will run as root.
If you were just logged in as yourself, it runs as though you ran the command.
You shouldn't use ~ for home in crontabs as an absolute path is better and reduces the chance of failure.
so
cd /Users/you/chess; /usr/bin/nice -n 15 ./cbspn >output.txt &
Using that example is better.
I guess because I'm using nice -20 I need to enter the crontab as root, eh? I noticed when testing my commands that I did not have permission to set a priority that high (or is it low)...

So mikkyo, is it possible to run several commands in one cron entry? I toyed with using a GUI cron utility (like Cronnix) so I wouldn't have to play with learning cron syntax, but when it read my cron tab it read each command in the one entry as the minutes, seconds, etc.

I'm guessing that cron entries are space-delimited?
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
mikkyo
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status: Offline
Reply With Quote
Jul 17, 2004, 03:25 PM
 
You can run several cronjobs in one crontab file, and you can execute several things with one cronjob by having it run a script that does everything.
So yes, and the potential is just about limitless.
See man crontab and man 5 crontab for more info.
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jul 23, 2004, 11:39 AM
 
I seem to run into problems when I try to get my folding process to run in a screen. Oh well, I'll just have to do some nifty stuff with the log files and php.

What's that script that keeps track of your clients based on their unitinfo.txt? Last time I checked out that thread regarding the issue, the tool was no longer available from the dude's website.
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
   
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 09:46 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,