Author Topic: Linux boot script question?  (Read 2019 times)

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #15 on: March 03, 2011, 04:07:33 am »


               Pretty sure that works.  Just piping it into a file instead of standard output (the screen).

Fairly certain you could also to ls -alF n*.*

Which would give you a listing of all files starting with n..
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #16 on: March 03, 2011, 03:18:19 pm »


               Ok here is what it shows by doing ls -alF n*.*

nwconfig.ini
nwconfig.exe
nwloader.exe
nwmain.exe
nwncdkey.ini
nwn.exe
nwnpatch.ini
nwnplayer.ini
nwserver.exe
nwtoolset.exe
nwtoolset.ini
nwupdate.ini

I see the nwserver when I do     ls         but not in this one ?
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #17 on: March 03, 2011, 07:21:38 pm »


               haha hey guys does this make sense to you ?

sudo apt-get install ia32-libs


./nwserver  not only worked  but DM can login too. Thanks guys .
               
               

               


                     Modifié par Knight_Shield, 03 mars 2011 - 08:10 .
                     
                  


            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #18 on: March 03, 2011, 10:22:48 pm »


               ahhh 64 bit environment.....

If you decide to run nwnx... I do have some binaries I compiled in 64 bit environment.  I don't think you'll need them if you just want to run 32 bit precompiled SO.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #19 on: March 06, 2011, 02:25:20 am »


               Ok guys I have been looking at the script Skildron advised .I was going to call it restart and have a cron call it every 5 min to see if server needed rebooting.

I'm NOT using nwnx keep in mind.

Question : where does the name of my module go in this thing.And once thats figured out is the rest right and if i call it every 5 minutes?

Here it is >>>>>>>>>>>>>>>>>>>>>>>.

#!/bin/bash
#nwservctl.sh
#control command for nwn server, requires empty-expect
# **** BASIC CONFIGURATION ****
# Num of log directory to keep
LOG_HIST_NUM=9
# Seconds to wait for server loading
SECONDS_TO_WAIT=60
#Default Countdown in seconds
COUNTDOWN=60
# nwserver command: nwserver or nwnstartup.sh for NWNX2
#NWSERVER_COMMAND="nwnstartup.sh" #NWNX2
NWSERVER_COMMAND="nwserver" #Basic nwserver
FIRST_EXIT_PHRASE="Stopping server in"
SECOND_EXIT_PHRASE="seconds please logout..."
# output passfrase to wait for module loaded
#PASS_PHRASE="0x08203e79" # NWNX2 init if you use nwnstartup.sh
PASS_PHRASE="running" # Basic nwserver
# **** END BASIC CONFIGURATION ****
# **** ADVANCED CONFIGURATION ******
# ONLY FOR EXPERTS
# start server command
NWSERVER_START="empty -f -i in.fifo -o out.fifo ./$NWSERVER_COMMAND"
# wait for loaded command
WAIT_LOADED="empty -w -t $SECONDS_TO_WAIT -i out.fifo -o in.fifo $PASS_PHRASE" # FOR nwnstartup.sh
# return output from server command
# use a timeout until all commands are debugged
CATCH_OUTPUT="empty -r -t 30 -b 8192 -i out.fifo"
# first line argument
ARG1="$1"
# exit code
EXCODE=0
# *** CODE ***
#check if arguments exist
if [ "x$ARG1" = "x" ] || [ "x$ARG1" = "xusage" ] || [ "x$ARG1" = "x--help" ]; then
   echo "Usage: `basename $0` start | restart [countdown [n]]" >&2
   echo "       `basename $0` stop [countdown [n]] | kill | status" >&2
   echo "       `basename $0` info [pid | pcpu | etime | pmem | vsz ] | --help" >&2
   echo "       `basename $0` <nwsever commands> if server is running" >&2
   exit 1
fi
# check if nwserver is running exit if command is not
if [ "$(pidof nwserver)" ] ; then
   if [ "x$ARG1" = "xstart" ] ; then
       echo "`basename $0` - nwserver already running..."
       exit 1
   else
       : # do nothing continue
   fi
else
   if [ "x$ARG1" = "xstart" ] ; then
       : # do nothing continue
   else
       echo "`basename $0` - nwserver is not running..."
       exit 1
   fi
fi

case $ARG1 in
start)
   # rotate logs
    if [ -d "./logs/logs.$LOG_HIST_NUM" ]; then
       rm -f -r "./logs/logs.$LOG_HIST_NUM"
    fi
    for ((ddest=$LOG_HIST_NUM; ddest >= 2 ; ddest--))
   do
       let "dsourc = $ddest - 1"
       if [ -d "./logs/logs.$dsourc" ]; then   
            mv -f "./logs/logs.$dsourc" "./logs/logs.$ddest"
       fi
   done
      #move log.0 in log.1
      mv -f ./logs.0 ./logs/logs.1
      mkdir ./logs.0            
   #end rotate logs
   
   shift
      NWSERVER_START="$NWSERVER_START $*"
   $NWSERVER_START
   echo "Starting nwserver please wait.."
   sleep 5
   $WAIT_LOADED
      
   if [ "$(pidof nwserver)" ]
   then
      echo "nwserver is running now"
   else
      echo "nwserver loading failed.."
      EXCODE=1
   fi
;;
stop|restart)
   if [ "x$2" = "xcountdown" ]
   then
       if [ "$3" -gt 0 ]
       then
           COUNTDOWN="$3"
       fi
       while [ "$COUNTDOWN" -gt 0 ]
       do
           $0 "say $FIRST_EXIT_PHRASE $COUNTDOWN $SECOND_EXIT_PHRASE"
           let "COUNTDOWN -= 10"
           sleep 10
       done
    fi  
   echo "exit" | empty -s -o ./in.fifo
   $CATCH_OUTPUT
   if [ "x$1" = "xrestart" ]
   then
   echo "restarting in 10 seconds pleas wait..."
   sleep 10
   $0 "start"
   fi
;;
info)
   case "$2" in
   pcpu|etime|pmem|vsz)
      ps -p "$(pidof nwserver)" -o "$2="
   ;;
   pid)
      echo "$(pidof nwserver)"
   ;;
   *)
      ps -p "$(pidof nwserver)" -o pid,comm,etime,pmem,vsz,pcpu
   esac   
;;
kill)   
   empty -k "$(pidof nwserver)"
;;
# with return output
status|help|listbans)
   echo "$ARG1" | empty -s -o ./in.fifo
   $CATCH_OUTPUT
;;
# no return output
playerpassword|dmpassword|adminpassword|oneparty|ilr|elc|difficulty|servername|autosaveinterval|pauseandplay|minlevel|maxlevel|maxclients|export|kick)
   echo "$*" | empty -s -o ./in.fifo
   #no output to catch
;;
#all other commands default send to nwserver
*)
   echo "$*" | empty -s -o ./in.fifo
   $CATCH_OUTPUT
esac
exit $EXCODE
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #20 on: March 06, 2011, 03:11:03 am »


               You'll see way at top there are two versions of the command to run nwserver.  One is without nwnx, you simply append your servers options, etc to the nwserver command.


Or you could simpely create a nwnstartup.sh file and use the nwnx command (you don't need to have the plugin to have the server startup routine)

would looks something like this:

[nwscript]
#!/bin/sh
#export LD_PRELOAD="./nwnx2.so"
./nwserver \\
-publicserver 1 \\
-servername "Your Server Name" \\
-dmpassword pass \\
-oneparty 0 \\
-pvp 2 \\
-difficulty 3 \\
-elc 1 \\
-ilr 0 \\
-reloadwhenempty 0 \\
-module "Your Module" \\
-pauseandplay 0 \\
-maxclients 40 \\
-servervault 1 \\
-maxlevel 40 \\
-gametype 3 \\
-autosaveinterval 0 \\
-playerpassword blblbl \\
-port 5121 \\
"$@"
#unset LD_PRELOAD
exit
[/nwscript]
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #21 on: March 06, 2011, 03:13:19 am »


               As for the cron job, you would have it test your process monitor say.. every 5 minutes....

You simply have to change your restart command to ./nwservctl.sh start
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #22 on: March 07, 2011, 02:13:41 am »


               I changed the line at the top like this


NWSERVER_COMMAND="nwserver -module mymodule" #Basic nwserver

comes back saying line 59 unknown token?  here is  line 59

case $ARG1 in
               
               

               
            

Legacy_Skildron

  • Sr. Member
  • ****
  • Posts: 421
  • Karma: +0/-0
Linux boot script question?
« Reply #23 on: March 07, 2011, 09:01:05 am »


               You have to run the script as ./nwservctl start to start your nwserver instance. Other than that, adding the module name inside the script, which I never did before, as the script offers lots of possibilities to communicate with the running nwserver, works fine - I just tried it out.

Greetings
Skildron
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #24 on: March 07, 2011, 09:26:58 am »


               Might have issues parsing the string like that, unfortunately my linux test box is outta comission for a couple days so I can't offer any help, other than what I suggested earlier, create a nwnstartup.sh file like the example above.

Then simply have your process monitor launch the server if the pid doesn't exist anywhere.  I wrote a slightly more detailed and elaborate process monitor than that, as mine will search to see if nwserver is hanging at maximum processor usage for more than 90 seconds if it is running.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #25 on: March 08, 2011, 04:12:52 pm »


               I cant get it to fire and my linux friend wont be in until friday.Could you post what you made work without the nwnx2 Skildron? I can copy it and paste my module name in it.Then if it doenst work for me I will know to trouble shoot something else .
               
               

               
            

Legacy_Skildron

  • Sr. Member
  • ****
  • Posts: 421
  • Karma: +0/-0
Linux boot script question?
« Reply #26 on: March 08, 2011, 11:05:46 pm »


               This is the nwservctl.sh script I use:

#!/bin/bash
#nwservctl.sh

#control command for nwn server, requires empty-expect

# **** BASIC CONFIGURATION ****

# Num of log directory to keep
LOG_HIST_NUM=9

# Seconds to wait for server loading
SECONDS_TO_WAIT=60

#Default Countdown in seconds
COUNTDOWN=60

# nwserver command: nwserver or nwnstartup.sh for NWNX2
#NWSERVER_COMMAND="nwnstartup.sh" #NWNX2
NWSERVER_COMMAND="nwserver -module Samaris" #Basic nwserver
FIRST_EXIT_PHRASE="Stopping server in"
SECOND_EXIT_PHRASE="seconds please logout..."

# output passfrase to wait for module loaded
#PASS_PHRASE="0x08203e79" # NWNX2 init if you use nwnstartup.sh
PASS_PHRASE="Module loaded" # Basic nwserver

# **** END BASIC CONFIGURATION ****

# **** ADVANCED CONFIGURATION ******
# ONLY FOR EXPERTS

# start server command
NWSERVER_START="empty -f -i ./in.fifo -o ./out.fifo ./$NWSERVER_COMMAND"

# wait for loaded command
WAIT_LOADED="empty -w -t $SECONDS_TO_WAIT -i ./out.fifo -o ./in.fifo $PASS_PHRASE" # FOR nwnstartup.sh

# return output from server command
# use a timeout until all commands are debugged
CATCH_OUTPUT="empty -r -t 30 -b 8192 -i ./out.fifo"

# first line argument
ARG1="$1"

# exit code
EXCODE=0

# *** CODE ***

#check if arguments exist
if [ "x$ARG1" = "x" ] || [ "x$ARG1" = "xusage" ] || [ "x$ARG1" = "x--help" ]; then
   echo "Usage: `basename $0` start | restart [countdown [n]]" >&2
   echo "       `basename $0` stop [countdown [n]] | kill | status" >&2
   echo "       `basename $0` info [pid | pcpu | etime | pmem | vsz ] | --help" >&2
   echo "       `basename $0` <nwsever commands> if server is running" >&2
   exit 1
fi

# check if nwserver is running exit if command is not
if [ "$(pidof nwserver)" ] ; then
   if [ "x$ARG1" = "xstart" ] ; then
       echo "`basename $0` - nwserver already running..."
       exit 1
   else
       : # do nothing continue
   fi
else
   if [ "x$ARG1" = "xstart" ] ; then
       : # do nothing continue
   else
       echo "`basename $0` - nwserver is not running..."
       exit 1
   fi
fi

case $ARG1 in
   start)
       # rotate logs
       [ -d ./logs ] || mkdir -p ./logs
       if [ -d "./logs/logs.$LOG_HIST_NUM" ]; then
           rm -f -r "./logs/logs.$LOG_HIST_NUM"
       fi
       for ((ddest=$LOG_HIST_NUM; ddest >= 2 ; ddest--));     do
           let "dsourc = $ddest - 1"
           if [ -d "./logs/logs.$dsourc" ]; then
               mv -f "./logs/logs.$dsourc" "./logs/logs.$ddest"
           fi
       done

       #move log.0 in log.1
       mv -f ./logs.0 ./logs/logs.1
       mkdir ./logs.0
       #end rotate logs

       shift
       NWSERVER_START="$NWSERVER_START $*"
       $NWSERVER_START
       echo "Starting nwserver please wait.."
       sleep 5
       $WAIT_LOADED

       if [ "$(pidof nwserver)" ]
       then
           echo "nwserver is running now"
       else
           echo "nwserver loading failed.."
           EXCODE=1
       fi
   ;;
   stop|restart)
       if [ "x$2" = "xcountdown" ]; then
           if [ "$3" -gt 0 ]; then
               COUNTDOWN="$3"
           fi
           while [ "$COUNTDOWN" -gt 0 ]; do
               $0 "say $FIRST_EXIT_PHRASE $COUNTDOWN $SECOND_EXIT_PHRASE"
               let "COUNTDOWN -= 10"
               sleep 10
           done
       fi
       echo "exit" | empty -s -o ./in.fifo
       $CATCH_OUTPUT
       if [ "x$1" = "xrestart" ]; then
               echo "restarting in 10 seconds please wait..."
               sleep 10
               $0 "start"
       fi
   ;;
   info)
       case "$2" in
           pcpu|etime|pmem|vsz)
               ps -p "$(pidof nwserver)" -o "$2="
           ;;
           pid)
               echo "$(pidof nwserver)"
           ;;
           *)
               ps -p "$(pidof nwserver)" -o pid,comm,etime,pmem,vsz,pcpu
           ;;
       esac
   ;;
   kill)
       empty -k "$(pidof nwserver)"
   ;;
   # with return output
   status|help|listbans)
       echo "$ARG1" | empty -s -o ./in.fifo
       $CATCH_OUTPUT
   ;;
   # no return output
   playerpassword|dmpassword|adminpassword|oneparty|ilr|elc|difficulty|servername|autosaveinterval|pauseandplay|minlevel|maxlevel|maxclients|export|kick)
       echo "$*" | empty -s -o ./in.fifo
       #no output to catch
   ;;
   #all other commands default send to nwserver
   *)
       echo "$*" | empty -s -o ./in.fifo
       $CATCH_OUTPUT
   ;;
esac

exit $EXCODE


I start it manually from the directory it resides in with
./nwservctl.sh start
Works fine for me.

Greetings

Skildron
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Linux boot script question?
« Reply #27 on: March 11, 2011, 07:13:22 pm »


               Woot ! ! ! After my linux friend beat me vigirously with a bamboo stick:pinched:':blink:' for using my Vista note pad ,he then copied your posted script  again in linux and installed it.
It works great.


Thanks again Skildron 
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #28 on: March 13, 2011, 04:56:35 am »


               Hey Skil, since we're talking bout the script here, maybe you can follow this.....


So you have the wait_loaded line like so:

SECONDS_TO_WAIT=120
PASS_RESPONSE="playerpassword\\n" # Basic nwserver
PASS_PHRASE="0x08203e79" # NWNX2 init if you use nwnstartup.sh
WAIT_LOADED="empty -w -t $SECONDS_TO_WAIT -i out.fifo -o in.fifo $PASS_PHRASE $PASS_RESPONSE"


So it waits for the nwnx init phrase, but I was expecting the -t to delay the command by that number of seconds, but according to the man page it simply is the amount of time to wait for an appropriate response.  Have a better idea on how to automate the removal of the password after more than a basic delay?


I've been mulling over something like the man page suggests....

A  better way to send the password to the supervised program is to read
      it from file:

           empty -s [common options] <./password-file


               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux boot script question?
« Reply #29 on: March 13, 2011, 05:01:06 am »


               Double Post
               
               

               


                     Modifié par Calvinthesneak, 13 mars 2011 - 10:06 .