arkaine23
04-02-2003, 04:33 PM
I want to make a shell script that launches a windows version of a DC client in wine whenever X starts.
I've already got a script that can do it while I'm in X. So I figure I just need to add a launch command in ~user/.xinitrc
I'm worried about the script spawning multiple processes when I switch between X and virtual terminals, so I need to add some subroutines to either detect other instances of wine or the CPU load so it won't start again if its already running. I'd also like a stop subroutine to stop the client when $1=stop.
I'm a little green with shell programming still and am stuck without a linux box for the time being (except for SSH and VNC which are my friends).
#!/bin/sh
cd /data/emu/windows
/usr/bin/nice -19 wine FAH3Consolewin32.exe -- -advmethods -forceasm > fold.log
Launches folding@home and wine from the dreictory /data/emu/windows and sends output to fold.log. Uses nice and some optional flags for the folding client.
Just need a subroutines or two and to get it to go when X starts.
bwkaz
04-02-2003, 06:50 PM
Umm... xinitrc doesn't run on VT switches...
The only thing you'll have to worry about is stopping the client when you exit X -- but if X is exiting, and the client has a window open, it'll shut down that way. Perhaps not cleanly, but it'll get shut down.
Doesn't F@H have a Linux client?
arkaine23
04-02-2003, 07:25 PM
No VT switches, that's good news. Now I just have to make it stop when X stops (I want it in the background). And I probably should look at making it loop a search for a running X and sleep for a few seconds each loop until it finds X, then start wine and folding. I'm not sure that wine can start in .xinitrc. or rather if X will need more time to load before wine can start.
There is a linux client. And its about 20% slower than running the windows client in wine. I made the little script, but some of my friends are just not very fanatical about running it all the time. Besides I need some practice with shell scripts. If I was on a linux box right now, I'd be testing scripts rather than brainstorming/posting. Will have to wait until later tonight when I get home before I can try anything...
I already have a perl script for running the linux client that's got quite a few features: it stops folding when the cpu goes under significant load from something else (the linux client is not nice with some apps on its own and this fixes that), fold on single or dual CPU's, delete a bad work unit, switch between assignment servers if unable to connect... I didn't write that one though.
http://www.vendomar.ee/%7Eivo/FAHLinux.txt -resources about folding in linux (mostly about the linux client though). But it does have kill commands to stop all the folding processes (usually there are about 6).
http://forum.folding-community.org/viewtopic.php?p=31225#31225 -another thread where I'm seeking some tips
perl script for native linux client-
#!/usr/bin/perl -w
# written by ptn on 11/04/02
# fix bug rename bad WU 11/12/02
# This program will start Folding gromacs and monitor the job. If the jobs seem
# hung up it will kill it and restart with no options i.e. tinker core and vice versa.
# If user run any program and use the cpu it will stop the job and continue on when
# user's job finish within 2 minutes. The waiting period loop between checks is
# around 2 mins, twice the sleep constant. One can also run the program with argument
# stop to kill folding process then exit the program.
# one should run the program like example below if c shell is the user's shell
# fold >& fold.log &
# if you decide to start this program automactically at boot up you could add the
# following line to the file rc.local
# su <folder user's name> -c "fold > /<fold_directory>/fold.log 2>&1"
# NOTE: user's normaly change the following constants: $FoldDir, $FAH3Console, $options
# and $sleep
# user's Folding command line options:
$options='-advmethods -forceasm';
# user's check time interval
$sleep = 30;
# user's minimum cpuload value, must be less than the set value it will start folding
$minld = 0.55;
# find hostname
$host=`hostname`;chop($host);
# user's Folding directory location , uncomment second line if dual cpus
$FoldDir="/data/$host";
$FoldDir2="/data/${host}2";
# user's maximum cpuload value, must be greater than the set value it will stop folding
if (-x $FoldDir2) {
$maxld = 2.3;
}else{
$maxld = 1.2;
}
# user's Folding program location
$FAH3Console="/home/troyw/bin/FAH3Console";
# initial value for stop flag
$stop=0;
#######################Do not edit below this line ######################################
if (! -x $FAH3Console) {
die "ERROR: can't find executable $FAH3Console\n";
}
if (defined $ARGV[0]) {
if ($ARGV[0] eq 'stop') {
system("kill `cat $FoldDir/fold.pid`");
&KillFold;
system("rm -f $FoldDir/core.*");
system("rm -f $FoldDir2/core.[0-9]*") if (-x $FoldDir2);
}else {
my $cmd = $0;
$cmd = $1 if ($cmd =~ m!/.*/([^ ]+)$!);
print "Usage:\n\t$cmd [stop]\n";
print "Example 1: To start smart folding process, type";
print "\n\t$cmd\n";
print "Example 2: To kill folding process and exit, type";
print "\n\t$cmd stop\n";
}
exit;
}
open(OUTFILE, "> $FoldDir/fold.pid") || die "ERROR: can't write to file $FoldDir/fold.pid\n";
print OUTFILE "$$";
close(OUTFILE);
$option = $options;
$killCount=0;
Begin:
$load = (&findLoad);
if ($load < $minld) {
#stop old hung up Folding jobs if exists.
&KillFold;
# check for bad Work Unit if job hung and clean the directory
if ($killCount > 1){
sleep ($sleep * 2);
my $curload = &findLoad;
if ($curload < $minld) {
&SearchBadWU($FoldDir);
&SearchBadWU($FoldDir2) if (-x $FoldDir2);
}
}
#start new Folding jobs
my $time = localtime(time);
print "Start Folding processes at: $time\n";
# print "load= $load , Invoking:\ncd ${FoldDir}; nice $FAH3Console $options\n";
system("\(cd $FoldDir; nice $FAH3Console $option\) &");
system("\(cd $FoldDir2; nice $FAH3Console $option\) &") if (-x $FoldDir2);
if ($option eq '') {
$option=$options;
}else {
$option='';
}
sleep $sleep;
}else {
my $time = localtime(time);
print "Waiting for load=$load to come down at: $time\n";
sleep $sleep;
$killCount=0;
goto Begin;
}
Inloop:
sleep $sleep;
$load = (&findLoad);
if ($load < $minld){
if ($stop) {
$stop=0;
&ContinueFold;
sleep $sleep;
}elsif ($stop==0) {
&KillFold;
goto Begin;
}
}elsif ($load > $maxld && $stop==0) {
&StopFold;
$stop=1;
sleep $sleep;
}
goto Inloop;
exit 1;
sub StopFold {
my $time = localtime(time);
print "STOP Folding processes at: $time\n";
my $ps = `ps -uxw | egrep FahCore | egrep -v grep | awk \'{print \$2}\'`;
$ps .= `ps -uxw | egrep FAH3Console | egrep -v grep | awk \'{print \$2}\'`;
@PS=split(' ',$ps);
foreach my $p (@PS) {
system("/bin/kill -s STOP $p");
}
}
sub ContinueFold {
my $time = localtime(time);
print "RESTART Folding processes at: $time\n";
foreach my $p (@PS) {
system("kill -CONT $p");
}
}
sub findLoad {
my $load;
open(INFILE,"< /proc/loadavg") || die "ERROR: Can't read file /proc/loadavg\n";
while(<INFILE>) {
$load=(split(' ',$_))[0];
last;
}
close(INFILE);
return $load;
}
sub KillFold {
my $time = localtime(time);
print "Kill Folding processes at: $time\n";
my $ps = `ps -uxw | egrep FAH3Console | egrep -v grep | awk \'{print \$2}\'`;
$ps .= `ps -uxw | egrep FahCore | egrep -v grep | awk \'{print \$2}\'`;
my @PS = split(' ',$ps);
foreach my $p (@PS) {
#print "kill $p\n";
system("kill -9 $p");
}
$killCount++;
}
sub SearchBadWU {
my $foldDir=pop(@_);
my $logFile = "$foldDir/FAHlog.txt";
my $line=`egrep 'Protein:' $logFile`;
my @protein = split(' ',$line);
$line = $protein[$#protein];
print "Last Protein in $logFile is $line\n";
if ($line eq 'Protein:') {
my $time = localtime(time);
print "Try to delete bad WUs and restart Folding at $time\n";
my $timestamp = $time; $timestamp =~ s/ /_/g;
system("mv -f $foldDir/queue.dat $foldDir/queue.dat.$timestamp; mv -f $foldDir/work $foldDir/work.$timestamp;mv -f $foldDir/initial.pdb $foldDir/initial.pdb.$timestamp; mv -f $foldDir/machinedependent.dat $foldDir/machinedependent.dat.$timestamp");
}
}