Find the answer to your Linux question:
Results 1 to 5 of 5
Hey Linux Guru's, Hoping you can help me here regarding my query, I've read through your forums and done a bit of googling to see that an automated reboot at ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    2

    Automated Reboot & Commands on a Debian Distro

    Hey Linux Guru's,

    Hoping you can help me here regarding my query, I've read through your forums and done a bit of googling to see that an automated reboot at a certain time has something to do with cron jobs but sadly this is completely all knew to me so would appreciate any help.

    My second task is then to run commands like the following command when the machine starts up again...

    screen -t s5 ./srcds_run -console -game cstrike -port 27025 +ip xxx.xxx.xxx.xx +map de_dust2 +maxplayers 11 -tickrate 100 -autoupdate

    it seems to me I need to edit the rd.local but when I open my file I don't really understand where I need to insert my command.


    Could anyone please be so kind to assist in educating me.

    Cheers,

    Tony

  2. #2
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    A cron job can be any regularly scheduled event. You could set up the computer to reboot everyday at a particular time, yes.

    Howto: Shutdown Linux Box Automatically

    For screen, are you booting into a graphical environment first or are you just booting into the console?

    I would put your command in your ~/.bash_profile.

    Code:
    exec screen...
    When you login, it will run the command. (You can use mingetty to autologin the console as well.)

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    2
    Ok so I think from this understanding all I would need to do to have a daily shutdown at 3am is the following

    contrab -e << opens up my contab file

    0 03 * * * /sbin/shutdown -h now <<add the following line

    Then save and close the file.

    My quick query is this doesn't mention anything about restarting the machine, I understand that might be me being a stupid window's desktop user mentality but can you just confirm that for me, ie a server will always reboot itself on a shutdown command.



    as for the ~/.bash_profile option, I read up and it appears that is something that runs when I log in via ssh (or at terminal) but what I am looking for is something that when the machine comes back up at 3am runs the programs without me needing to do anything.

    Basically I'm running a Linux box that hosts game servers so to always keep the game servers fresh, it helps to reboot them.
    What I want to do is have an automatic reboot every night at 3am and the game servers to come straight back up without me needing to do anything.

    Btw Thank you for your assistance so far.

  4. #4
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    No, it won't reboot with the shutdown or halt commands. But there is also a reboot command or you can use the -r flag with shutdown.

    ~/.bash_profile would run everytime the user logged in, yes.

    Given your goal, I would look to set it up as a daemon and link it to start at a particular run level. Fortunately, if you can think of something, someone probably has already done it and that is the case here. I found this script for doing just that.

    Code:
    #!/bin/sh
    #
    # Start the Counter-Strike dedicated server.
    #
    # AUTHORS :
    #
    # Julien Escario ( pandemik@asylog.net )
    # &
    # Cedric Rochat ( crochat@younics.org )
    #
    # ===========================================
    #
    # What you need:
    #
    # Linux
    # awk
    # screen
    # the hlds_l & cstrike-files
    #
    # How to use:
    #
    # Edit the DIR-Var to fit your system (just contains the path to the dir that contains 
    # hlds_run)
    # Edit the PARAMS-Var to fit your needs
    # - standard is startup as LAN-server
    #
    # When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
    # scripts for starting the services
    # Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
    # ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/S90hlds
    # ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/K50hlds
    #
    # Or use it manualy like:
    # /etc/rc.d/init.d/hlds start
    # /etc/rc.d/init.d/hlds stop
    #
    # How to see the server-console:
    #
    # Just type in: screen -r cstrike
    # More info about screen can be found by typing "man screen" or using this nice link
    # http://server.counter-strike.net/help/linuxscreen.html
    #
    # If you don't want to start the server as root you have to change this:
    # add the var CS_USER and uncomment it
    # change the lines at the "start-block"
    #
    # You must be logged in as this user to re-attach the screen!
    #
    # DOC by jwm (jwm@counter-strike.de)
    
    
    # Edit and uncomment it to run the server as non-root
    CS_USER="agmar"
    #
    # DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
    DIR=/home/agmar/hlds3
    #
    # LAN-server:  
    PARAMS="ulimit -c unlimited && -binary ./hlds_i686 -game cstrike  -insecure +sv_lan 0 +maxplayers 26 +port 27018 +exec server.cfg +map de_dust2 -debug"
    #PARAMS="-game cstrike -pingboost 1 -tos -zone 8096 -heapsize 524000 +sv_lan 0 +maxplayers 21 +map de_dust +mp_roundtime 1.92 +port 27015 +ip 89.174.100.155" 
    
    #
    # Internet-server:
    #PARAMS="-game cstrike +ip YOUR_ONLINE_IP +map de_dust +maxplayers 8"
    
    clear
    PATH=/bin:/usr/bin:/sbin:/usr/sbin
    DAEMON=$DIR/hlds_run
    NAME=agm
    DESC="CounterStrike dedicated server"
    
    case "$1" in
    start)
    if [ -e $DIR ];
    then
    echo "Starting $DESC: $NAME"
    cd $DIR
    # Change the lines for running as non-root!
     screen -d -m -S $NAME $DAEMON $PARAMS
    #nice -n -20 screen -d -m -S $NAME $DAEMON $PARAMS
    # nice -n -20  su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
     
    else echo "No such directory: $DIR!"
    fi
    ;;
    
    stop)
    if [[ `screen -ls |grep $NAME` ]]
    then
    echo -n "Stopping $DESC: $NAME"
    kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
    echo " ... done."
    else
    echo "Coulnd't find a running $DESC"
    fi
    ;;
    
    restart)
    if [[ `screen -ls |grep $NAME` ]]
    then
    echo -n "Stopping $DESC: $NAME"
    kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
    echo " ... done."
    else
    echo "Coulnd't find a running $DESC"
    fi
    
    echo -n "Starting $DESC: $NAME"
    cd $DIR
    screen -d -m -S $NAME $DAEMON $PARAMS
    echo " ... done."
    ;;
    
    status)
    # Check whether there's a "hlds" process
    # if "checkproc" is installed, you can use this:
    # checkproc $DIR/hlds_run && echo "CS-Server RUNNING" || echo "CS-Server NOT RUNNING"
    # (thx to commander)
    ps aux | grep -v grep | grep hlds_r > /dev/null
    CHECK=$?
    [ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
    ;;
    
    *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
    ;;
    esac
    
    exit 0
    Debian defaults to runlevel 2, so that's where you'd want to link it.

    An introduction to run-levels
    RunLevel - Debian Wiki

  5. #5
    Just Joined!
    Join Date
    Nov 2010
    Posts
    1

    Smile I have the solution...

    If you want to solve this problem type $ init 6 <ENTER> on the command line. I had this problem before and this worked perfectly. Please respond with the results.

Posting Permissions

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