Click to See Complete Forum and Search --> : running applications on boot


CaptainPinko
02-24-2003, 09:11 PM
this is not one but actually two related questions

1) i want Folding@Home (http://folding.stanford.com) (a distributed application for protien folding kinda like SETI@Home but for something useful )to start as soon as possible when the computer boots up, i assume there must be a script or something that i could add a line to do this


2) there are some applications i would like to start as soon as i logon onto KDE... is this what ~/.kde/AutoRun is for? could i just link the executable into this folder?

and as a sort of aside
3) where could i find information on the linux boot sequence, like in ms-dos i know it goes io.sys, msdos.sys, command.com, config.sys, autoexec.bat yadda yadda yadda

GaryJones32
02-24-2003, 11:59 PM
well i can sort of tell you how bootup works.

there is a file, mine is in /etc called inittab

that tells the bootup the runlevel

runlevel 2 enters /etc/rc2.d

all the files in rc2.d are links to files in /etc/init.d

All the linked files in the run levels start with S for start
or K for kill.

links are started in numerical order

links with the same number are started in alphabetical order

you can also easily add things to start when you start x

.kde/Autostart is a little strange so using the other scripts is easier but yes that is one possibility.

you could add something easily into startkde
type: which startkde to find it
or the scripts that run in your home dir like .xsession if you have one -- the possible ways to startx are so endless it's
hard to talk about
good idea to backup these files first.
to start a process in a shell script you

exec thisApp &

the & sets it going in the background so it's not too in the way.
background start is important for a windowed thing you try to start as the same time as window manager.

i don't use display managers so i don't know how they work but if you use startx then you can make your own .xinitrc file in your home dir to controll x startup.
startx controlls or passes arguments to a program called xinit
through a system wide script called xinitrc
find it by reading startx
find startx with which startx
systemwide xinitrc is prob listed as the variable sysclientrc or something

copy the systemwide xinitrc to your home dir and rename it
.xinitrc
and hack away at it...(only if it's actually doing the work)
sometimes
the systemwide xinitrc just reads another systemwide file
Xsession that in turn reads a home dir script .xsession
and other files
(possibly the best one to use is a personal .xsession file)
you just have to read them and see what they are doing
it helps to be operating from the terminal so when you screw up you just get kicked back to the terminal rather than getting caught kicked back to that darn graphical login screen...


hope this helps a little

chrism01
02-25-2003, 08:57 AM
To add your own stuff to the startup sequence, append to the ned of the /etc/rc.local file.
That's what its for (hence the name....)

devastator
02-25-2003, 12:31 PM
I would suggest to look for a readme in the init.d directory.
There could also be a skeleton file which you just have to change a bit(In my distro ist was explained well,I use SUSE 8.1).

CaptainPinko
02-25-2003, 02:35 PM
Originally posted by chrism01
That's what its for (hence the name....)

huh? plz explain the "hence its name" part :confused:

chrism01
02-26-2003, 01:26 PM
Sorry: most startup files are in a series of dirs beginning with "rc"; eg rc5.d contains files to start/stop for runlevel 5 ie everything plus x-windows..
Each runlevel 0-6 has a similar dir.
rc.local means the rc file for "localisations" ie extras to start for this machine only. This file should not be trashed even during an upgrade of the same distro. Its where you can safely customize the startup of each machine without breaking the vendor supplied scripts.
HTH
:)

arkaine23
04-03-2003, 06:05 PM
Scripts and info by OC.com Team 32 folders. Join our team if you want !!!:

For scripts to launch linux native clients-

Launch your script at startup by sticking a lauch command in one of your rc files, like rc.local. (It may vary by distro, though rc.local usually works. In gentoo, I use /etc/conf.d/local.start).

Most will want to fold in wine with the windows client, but for large networks (aka linux borging) its better to use the perl script. Both are listed below. You can copy the text and paste it into a text file. chmod +x the file and stick it in a directory in your PATH.

Here's what an example launch command might look like:
su troyw -c '/home/troyw/bin/fold > /data/emu/fold.log' &

To translate- become user troyw and launch the script at /home/troy/bin named fold, output goes to a file located at /data/emu called fold.log. Run in background. I put this in /etc/conf.d/local.start (but that's gentoo), you'll probably stick it in an rc script in most distros.

To set up a cron job to restart once per day.
as a regular user that owns the script:
crontab -e

0 12 * * * /home/troyw/bin/fold stop > /dev/null
1 12 * * * /home/troyw/bin/fold > /data/emu/fold.log

Stop the script fold at noon daily and restart it at 12:01.

The following requires perl, awk, and grep be installed on a system (probably have these by default in most cases). What id does:

Dual: This script will run 2 instances if you have dual CPU's.

Idling: It folds as long as the CPU load from other apps is not greater than the variable $minld, which is set at 55%. The user may change this to any number between 0 and 100. It is an idle feature that was needed to keep folding nice when a very few apps are running such as OpenOffice, apps which are negatively affected by linux folding@home's inability to idle correctly sometimes. If the load from anything but folding becomes more than $minld, then the process is paused until the load drops below $minload. It will resume without any loss in progress on the current frame.

Command flags: This script also is set to run the gromacs command flags by default. Gromacs work units are faster on any CPU that can use SSE or 3dNow! optimizations. This is controlled by the variable $options.

The script will delete a work unit it thinks one is bad (due to it taking too long on a frame) and get a new one. It'll also toggle between gromacs and tinker flags if it has trouble connecting. In essence it tries to get work from a different assignment server in order to reduce downtime.

Other stuff: $FAHConsole needs to be set to the name of your linux folding client. You also need to chmod +x the client. And run it manually to set the config file to your username and team number.
$FoldDir needs to be set to the directory where your linux folding client is stored.

Perl script by overdoze:

# 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.$tim
estamp;mv -f $foldDir/initial.pdb $foldDir/initial.pdb.$timestamp; mv -f $foldDir/machinedependent.dat $fo
ldDir/machinedependent.dat.$timestamp");
}
}





Winefold shell script by Arkaine:

#!/bin/sh
# go to directory where windows client resides
cd /data/emu/windows
# launch wine with nice level 19 and windows client with advmethods and forceasm flags and send output to file
/usr/bin/nice -19 wine FAH3Console.exe -- -advmethods -forceasm > fold.log

#Note: You may have to remove the nice -19 part. It works in gentoo, but I can't get it to work like that in redhat.


Note: For both scripts, you need to place them in your PATH. For me a good spot is /home/username/bin. You also need to chmod +x the script so it will be executable.

I haven't been able to get this wine script to run at startup or when X starts just yet. So for now you have to launch it manually in a terminal.