Script for starting/stopping Boinc

Questions and Answers : Unix/Linux : Script for starting/stopping Boinc
Message board moderation

To post messages, you must log in.

AuthorMessage
Profile Charles Dennett

Send message
Joined: 29 Apr 00
Posts: 27
Credit: 18,785
RAC: 0
United States
Message 872 - Posted: 23 Jun 2004, 23:11:35 UTC
Last modified: 23 Jun 2004, 23:13:09 UTC

When I first joined Boinc Beta, I wrote a script to stop/start/restart Boinc. It is used at boot time to start Boinc and put it in the background, although it can be used at any time. I wrote it for my RedHat 9 system. There is a section in the script where you would customize it for your situation. Installation and usage instructions are in comments in the code. If you are familiar with how boot scripts work, you should have no problem.

The script works for me on my system. YMMV.

The script can be grabbed from:

http://www.dennett.org/boincctl

I had made it available to the Beta gang so I figured I'd make it available here, too.

Charlie


ID: 872 · Report as offensive
Profile Toby
Volunteer tester
Avatar

Send message
Joined: 26 Oct 00
Posts: 1005
Credit: 6,366,949
RAC: 0
United States
Message 1048 - Posted: 24 Jun 2004, 8:08:09 UTC

Works like a charm in gentoo (with a couple tweaks). Thanks!
ID: 1048 · Report as offensive
Caliban83

Send message
Joined: 13 Feb 00
Posts: 1
Credit: 21,546
RAC: 0
Germany
Message 2884 - Posted: 30 Jun 2004, 17:03:13 UTC - in response to Message 1048.  

But doesn't work with Suse 9.1
It claims, that "functions" doesn't exist. Do you know a way to make it work?
ID: 2884 · Report as offensive
Profile Charles Dennett

Send message
Joined: 29 Apr 00
Posts: 27
Credit: 18,785
RAC: 0
United States
Message 2931 - Posted: 1 Jul 2004, 2:08:54 UTC - in response to Message 2884.  

> But doesn't work with Suse 9.1
> It claims, that "functions" doesn't exist. Do you know a way to make it work?
>

Remove the line that reads in /etc/init.d/functions.

Change the stop function to use the pkill command rather than killproc. killproc is a function defined in /etc/init.d/functions. pkill is a regular command. The line is there, it's just commented out. (Unless Suse does not support pkill. Then you'll need to figure out how to stop the process some other way.)



ID: 2931 · Report as offensive
Profile The Dreamer
Volunteer tester
Avatar

Send message
Joined: 15 May 99
Posts: 10
Credit: 4,321,921
RAC: 0
United States
Message 3220 - Posted: 1 Jul 2004, 16:17:46 UTC - in response to Message 2931.  
Last modified: 1 Jul 2004, 16:20:22 UTC

Here's my script that I use on all my Linux boxes (RedHat 7.2, RedHat 7.3, RHEL3, SuSE 7.3, SuSE 8.2):


<PRE>
#!/bin/bash
# chkconfig: - 95 5
# description: boinc
case "$1" in
start)
cd /var/.seti
./boinc -allow_remote_gui_rpc > boinc.log 2>&1 &
;;
stop)
pid=`ps -e | grep -v K | awk '$NF~/boinc/ {print $1}'`
if [ "X$pid" != "X" ]; then
kill $pid
fi
;;
reload|restart)
$0 stop
sleep 10
$0 start
;;
refresh)
pid=`ps -e | grep -v K | awk '$NF~/boinc/ {print $1}'`
if [ "X$pid" == "X" ]; then
$0 start
fi
;;
*)
echo "usage $0 {start|stop|restart|refresh}"
;;
esac
exit 0
</PRE>

--
You may be a dreamer, but I'm The Dreamer, the definite article you might say!
ID: 3220 · Report as offensive
Jörg Waßmer

Send message
Joined: 8 May 00
Posts: 1
Credit: 78,350
RAC: 0
Germany
Message 9088 - Posted: 17 Jul 2004, 19:11:05 UTC
Last modified: 17 Jul 2004, 19:19:09 UTC

Here is my script:
#!/bin/sh

# boinc-service
#
# Linux script for running  as a system service.
#
# Author :  Jörg Waßmer 
# Version:  1.0, 2004/07/17
#
# This file is absolutely free to use and to modify.
# The author takes no warranty for anything.
# 
# Commands used by this script:
# basename, cat, pgrep, pkill, ps, readlink, su, tail, which
#
# Tested on Mandrake Linux 10.0 and SuSE Linux 9.0
#
### BEGIN INIT INFO
# Default-Start:  3 5
# Default-Stop:
# Description:    The Boinc daemon
### END INIT INFO


# Configuration:
#  BOINC_HOME : The directory where boinc is installed.
#  BOINC_BIN  : The full path to the boinc executable.
#  BOINC_USER : Username to run boinc as.
#    You have to run this script as root if you want to change the username.
#    You also have to accomodate the permissions of your boinc directory.
#    I recommend running boinc NOT as root.
#  BOINC_LOG  : Full path of the file to direct output from boinc to.  
#  BOINC_OPT  : Options for the boinc command.
BOINC_HOME="~/boinc"
BOINC_BIN="$BOINC_HOME/boinc"
BOINC_LOG="/dev/null"
BOINC_USER=$USERNAME
BOINC_OPT="-return_results_immediately"
PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"



# Test wether boinc is runnning.
checkRunning()
{
  pgrep -u $BOINC_USER -f $BOINC_BIN >>/dev/null 2>>/dev/null
  return $?
}


start()
{
  checkRunning
  if (($?==0)); then
    echo "boinc is already running"
  else
    echo -n "Starting boinc..."    
    
    cd $BOINC_HOME	
    su $BOINC_USER -c "$BOINC_BIN $BOINC_OPT >>$BOINC_LOG 2>>$BOINC_LOG &"
    sleep 1
    checkRunning
    if (($?==0)); then
      echo "success"
    else
      echo "failed"
      exit 1
    fi     
  fi  
}

stop()
{
   checkRunning
   if (($?==0)); then
     echo -n "Stopping boinc..."
     pkill -u $BOINC_USER -f $BOINC_BIN
     if (($?==0)); then
       echo "success"
     else
       echo "failed"
       exit 1
     fi  
   else
     echo "boinc is not running"  
   fi  
}

restart()
{
   stop
   sleep 10
   start
   return $?
}

status()
{
  checkRunning
  if (($?==0)); then
    echo "boinc is running"
    tail -20 "$BOINC_LOG"
  else
    echo "boinc is not running"
  fi  
}


# Tests wether the given command exists
testcmd()
{
  which $1 >>/dev/null
  if (($?!=0)); then
    echo "Error: required command $1 not found, check your PATH"
    exit 1
  fi
}


# Checks wether this script is properly configured.
testConfiguration()
{
  testcmd which
  testcmd basename
  testcmd cat
  testcmd pgrep
  testcmd pkill
  testcmd ps
  testcmd readlink
  testcmd su
  testcmd tail

  if [ ! -d "$BOINC_HOME" ]; then
    echo "ERROR: BOINC_HOME $BOINC_HOME is not a directory."
    exit 1
  fi

  if [ ! -x "$BOINC_BIN" ]; then
    echo "ERROR: BOINC_BIN $BOINC_BIN is not an executable."
    exit 1
  fi
}





#
# main program
#

[ -n $BOINC_USER ] || BOINC_USER=$USERNAME
[ -n "$BOINC_LOG" ] || BOINC_LOG="/dev/null"
[ -L $BOINC_BIN ] && BOINC_BIN=`readlink $BOINC_BIN`
    

testConfiguration



case "$1" in
  start) 
    start
  ;;
  
  stop)
    stop
  ;;
  
  restart)
    restart
  ;;
  
  status)
    status
  ;;
  
  *)
    echo "Usage:     `basename $0` start|stop|restart|status"
    exit 1
  ;;
esac
ID: 9088 · Report as offensive
general^malfunkshun

Send message
Joined: 28 Mar 03
Posts: 1
Credit: 126,963
RAC: 0
United Kingdom
Message 29992 - Posted: 25 Sep 2004, 16:08:13 UTC - in response to Message 2884.  
Last modified: 25 Sep 2004, 16:10:06 UTC

> But doesn't work with Suse 9.1
> It claims, that "functions" doesn't exist. Do you know a way to make it work?
>

this had me stumped for a while but i got there (not bad for a first time linux noob) anyway try this for Suse 9.1


firstly download the client for linux, in your home folder make a new folder called BOINC. Extract the client to

/home/youraccount/BOINC

make sure the permissions are correct and run it for the first time from console like this....

cd /home/youraccount/BOINC; ./boinc_4.09_i686-pc-linux-gnu

you will be prompted for the project URL and your account passcode, have them ready and enter as required. Now kill boinc from console thus...

killall boinc_4.09_i686-pc-linux-gnu

in /home/youraccount/BOINC create a text file and name it boinc.log


DO THE REST AS ROOT!!!


log in as root

on the desktop create a new text file and name it boinc.start.
open the text file and type this (including blank lines)

#!/bin/bash

#description: boinc start

cd /home/youraccount/BOINC; ./boinc_4.09_i686-pc-linux-gnu >boinc.log 2>/dev/null&

close and save the file them move it to

/etc/init.d

next create a symlink in console...

cd /etc/init.d/rc5.d
ln -s /etc/init.d/boinc.boot

you now need to go to /etc/init.d/rc5.d there find the file boinc.boot and rename it S21boinc.boot

and thats all you need to get boinc to run at boot and stay running without the console open (output will be in /home/youraccount/BOINC/boinc.log and errors will be in boinc.main).

to get Boinc to stop when you change runlevel you can do the following

log in as root

create a text file on desktop called boinc.stop and in it type this....

#!/bin/bash

#description: boinc stop

killall boinc_4.09_i686-pc-linux-gnu

close it amd move it to /etc/init.d

in console create a symlink as before

cd /etc/init.d/rc5.d
ln -s /etc/init.d/boinc.stop

again go to /etc/init.d/rc5.d and rename the file K01boinc.stop

job done, this method, while extremely simplified will start boinc last at boot and stop it first at log off.

(remember that /home/youraccount/ is your home directory eg. /home/malfunkshun/BOINC)


on further fiddling it seems that the dreamers script will work for both start and stop but needs seperate symlinks named similarly to the above (symlinks MUST be prefixed Sxx to start or Kxx to stop)
eg if you name the dreamers script 'Boincscript' and put it in /etc/init.d you might be able to get it to run by creating a symlink thus.....

cd /etc/init.d/rc5.d
ln -s /etc/init.d/Boincscript

then rename it S21Boincsript

and likewise a stop symlink might be....

cd /etc/init.d/rc5.d
ln -s /etc/init.d/Boincscript

then rename it K01boincscript
but this would depend on wether the dreamers scrip determines the BOINC clients status before acting, if it does it should work.
Hope this helps :)

ID: 29992 · Report as offensive

Questions and Answers : Unix/Linux : Script for starting/stopping Boinc


 
©2024 University of California
 
SETI@home and Astropulse are funded by grants from the National Science Foundation, NASA, and donations from SETI@home volunteers. AstroPulse is funded in part by the NSF through grant AST-0307956.