Results 1 to 17 of 17

Thread: Startup/Shutdown cleanly in Linux

  1. #1
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up Startup/Shutdown cleanly in Linux

    Ok I've managed to get this running perfectly on my Gentoo Linux machine, but how should I get it to startup and shutdown cleanly? I can write a script or run a crontab to start it but how would I stop it automatically. I assume killall foldrajlite would not be appropriate

    Better still if I could run to behave much like the windows service where it will only upload at 5000 structures and not upload at shutdown. Thanks

  2. #2
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up

    Not to worry got it sorted ... delete the lock file

  3. #3
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up

    However I find that if I delete the .lock file the client will stop after the next structure is completed ... but then uploads the data. I've put in a script to run the client and stop the client into my default run level.
    Code:
    #!/sbin/runscript
    
    start() {
    
            ebegin "Starting SLRI-Folding"
            cd ${FOLDING_DIR}
            ./foldit >&/dev/null&
            eend $?
    }
    
    stop() {
            ebegin "Stopping SLRI-Folding"
            cd ${FOLDING_DIR}
            rm foldrajlite.lock
            eend $?
    }
    Is there a way to prevent it from uploading when I stop the client, and only upload every 5000? Since proberbly by the time it starts to upload, the machine may well be shutdown. Thanks

  4. #4
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    If it's linux, then it's supposed to wait until all threads have been stopped before it shuts down. That's normally why you see something lik e"Killing all threads", then it shuts down. Your conenction should still be there, and the machine should still be running when the client begins upload, because the client doesn't actually stop, then restart to upload, it's still running.

  5. #5
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up

    Thanks for the reply Darkness, upon shutdown the lock file does get deleted but unfortunately the client is getting killed I'm getting this in the error.log
    Code:
    ERROR: [001.001] {foldtrajlite.c, line 1095} Caught sig 15
    Anyone know of any other way of starting this at boot and closing it cleanly at shutdown?

  6. #6
    Ancient Programmer Paratima's Avatar
    Join Date
    Dec 2001
    Location
    West Central Florida
    Posts
    3,296
    How about:

    rm foldrajlite.lock
    sleep (some number)

  7. #7
    try sending it the letter 'Q'. Easiest way to do this would probably to write up a little proggie that starts up the client, and then just goes to sleep. When it gets the kill signal it can send the client the letter 'Q' through the redirected standard input and wait for it to finish up.

  8. #8
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up

    I thought about that, and I'll give it a go The problem that I can see is that sometimes it takes a while to to upload, could be having problems connecting to the server, and if it's not uploaded by the sleep counter stops the client will get "killed". Anyone knows how long it takes for the client to timeout when connecting to the server?

    Thanks for the suggestions guys ... keep 'em coming

    edit: Anyone know how you can stop the client from uploading when shutdown, without stopping the automatic upload every 5000? Heres a snip from the readme file on the windows service.
    The Windows version of the client can be set up to run as a normal Windows NT
    service, so that it will start automatically whenever your computer starts up
    and run in the background until you shut down. Structures will be uploaded
    every 5000 still, and buffered for later upload at shutdown (so your shutdown
    procedure will not be delayed)
    can this behaviour be done on the Linux client?
    Last edited by Mpemba Effect; 11-02-2002 at 04:51 PM.

  9. #9
    Senior Member
    Join Date
    Mar 2002
    Location
    MI, U.S.
    Posts
    697
    This might be a better way to do it:

    Code:
    #!/bin/sh
    
    rm -f foldtrajlite.lock
    
    while ps -C foldtrajlite >/dev/null 2>&1 ; do
        sleep 1
    done
    ps -C <process name> prints out a line based on whether or not <process name> is running. The exit status of ps is also successful if the process is running, and unsuccessful otherwise. So this will remove the lock file, check if foldtrajlite is running, and as long as it is, it will sleep one second and then check again.

  10. #10
    Team Overclockers UK Mpemba Effect's Avatar
    Join Date
    Nov 2002
    Location
    Olympus Mons
    Posts
    15

    Thumbs up

    Oh yes mate! Thats solved it ... works very nicely, cheers bwkaz ... that was the missing line I needed For anyone else who's having the same problems heres the script i'm using:
    Code:
    #!/sbin/runscript
    
    start() {
    
            ebegin "Starting SLRI-Folding"
            cd ${FOLDING_DIR}
            ./foldit >&/dev/null&
            eend $?
    }
    
    stop() {
            ebegin "Stopping SLRI-Folding"
            cd ${FOLDING_DIR}
            rm -f foldtrajlite.lock
            while ps -C foldtrajlite >/dev/null 2>&1 ; do
                    sleep 1
            done
            eend $?
    }
    Thanks for everyones help

  11. #11
    Ancient Programmer Paratima's Avatar
    Join Date
    Dec 2001
    Location
    West Central Florida
    Posts
    3,296
    Good show, bwkaz!

    That "ps -C" has come in handy a couple of times now.

  12. #12
    Senior Member
    Join Date
    Mar 2002
    Location
    MI, U.S.
    Posts
    697
    Hey thanks. I had been using ps -ax | grep foldtrajlite for a while, but that would spit out spurious extra lines and stuff, so checking through the ps documentation for something better found -C. Works wonderfully.

  13. #13
    What is ps -C? -C is an illegal option on Solaris 8.

  14. #14
    Member vsemaska's Avatar
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    49
    The ps option -C in LINUX is select by command name. For example,

    # ps -C sshd

    PID TTY TIME CMD
    1069 ? 00:00:18 sshd
    27818 ? 00:00:07 sshd

  15. #15
    Senior Member
    Join Date
    Mar 2002
    Location
    MI, U.S.
    Posts
    697
    From the Linux ps manpage:

    Code:
    COMMAND-LINE OPTIONS
           This version of ps accepts several kinds of options.
                  Unix98 options may be grouped and must be preceeded by a dash.
                  BSD options may be grouped and must not be used with a dash.
                  GNU long options are preceeded by two dashes.
           Options of different types may be freely mixed.
    -C is preceded by a single dash, and is therefore (as far as I can tell, anyway) a Unix98 option. Perhaps Solaris' ps isn't Unix98 or something?

  16. #16
    <HaloJones> What is ps -C? -C is an illegal option on Solaris 8.

    Yes, but solaris 8 has pgrep.

  17. #17
    I didn't see one posted previously.... Here is the script that you have above, but re-written for Red Hat.

    #!/bin/sh
    #
    # description: Foldit

    # Source function library.

    . /etc/rc.d/init.d/functions

    # Change Directories
    cd /usr/local/distribfold

    RETVAL=0

    # See how we were called.

    case "$1" in
    start)
    ./foldit > /dev/null 2>&1 &
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
    action "Starting Foldit: " /bin/true
    else
    action "Starting Foldit: " /bin/false
    fi
    ;;
    stop)
    rm -f foldtrajlite.lock
    RETVAL=$?
    while ps -C foldtrajlite >/dev/null 2>&1 ; do
    sleep 1
    done
    if [ $RETVAL -eq 0 ]; then
    rm -f /var/lock/subsys/slamd
    action "Stopping Foldit: " /bin/true
    else
    action "Stopping Foldit: " /bin/false
    fi
    ;;
    status)
    if [ -e foldtrajlite.lock ]; then
    echo "Foldit is Currently Running";
    else
    echo "Foldit is Currently Stopped";
    fi
    ;;
    restart)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
    *)
    echo "Usage: foldit {start|stop|restart|status}"
    exit 1
    esac

    exit $RETVAL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •