Author Topic: Linux NWServer restart  (Read 708 times)

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« on: November 09, 2010, 03:26:34 am »


               http://nwn.bioware.c...ml?post=6367678



Alright so I'm taking the plunge into Linux here and between Cron job and shell scripts here, trying to get my server to run automated reboots.  I just have a script called autorboot.sh that is executed by cron.

And all the reboot script is supposed to do is execute ./nwservctl.sh restart.

However I'm encountering issues with the commands hanging at the prompt.  I've only moderate linux experience and this is driving me crazy as to why this should not work.

Anyone able to provide me some suggestions?
               
               

               
            

Legacy_Lord Sullivan

  • Hero Member
  • *****
  • Posts: 671
  • Karma: +0/-0
Linux NWServer restart
« Reply #1 on: November 09, 2010, 05:13:50 pm »


               are you using NWNx2? if so, do you have the nwnstartup.sh script in your NWN directory?



Explain your setup as best you can... that can help to find out what it is that is the issue.
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #2 on: November 09, 2010, 05:43:13 pm »


               yes have nwnx2. yes the nwnstartup.sh script is in my nwn directory. The script will go to the directory when executing commands.

My issues are coming in the special pipe files in.fifo, out.fifo. Soon as any operation is attempted on the pipe files the system hangs there, making me think the connection is not open on both ends properly. I created the files using mkfifo -m 666 ./in.fifo ./out.fifo.

basically I have an ubuntu box that on startup executes a script called boot.sh. It should execute the nwservctl.sh start command, which should in turn launch nwserver. no problem there. However once the nwserver instance is running any of the commands sent through nwservctl.sh seem to hang the term window I execute them from.

I'm guessing I've done something wrong with the FIFO files, or I'm not detaching process properly.

EDIT:  I suppose I should note that my info command in the nwservctl.sh is working.  It doesn't touch any of the fifo files.
               
               

               


                     Modifié par Calvinthesneak, 09 novembre 2010 - 06:42 .
                     
                  


            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #3 on: November 09, 2010, 05:59:53 pm »


               

FIFO Special Files

A FIFO special file is similar to a pipe, except that it is created in a different way. Instead of being an anonymous communications channel, a FIFO special file is entered into the file system by calling

mkfifo
.
Once you have created a FIFO special file in this way, any process can open it for reading or writing, in the same way as an ordinary file. However, it has to be open at both ends simultaneously before you can proceed to do any input or output operations on it. Opening a FIFO for reading normally blocks until some other process opens the same FIFO for writing, and vice versa.



I think my issue is somewhere with the last bit of that statement, my fifo is blocking....
               
               

               


                     Modifié par Calvinthesneak, 09 novembre 2010 - 06:07 .
                     
                  


            

Legacy_Skildron

  • Sr. Member
  • ****
  • Posts: 421
  • Karma: +0/-0
Linux NWServer restart
« Reply #4 on: November 09, 2010, 07:55:55 pm »


               Did you install the "empty-expect" package? If not, do so by executing
sudo apt-get install empty-expect
from a terminal window (aka command line). As the empty command opens the fifos for communication, that might be your problem.

HTH
Greetings
Skildron
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #5 on: November 09, 2010, 08:01:30 pm »


               Sure did Skil.  As I said some of the commands work... start for example will happily launch the nwserver with the startup.sh script....



The way I understand it is the communication to a fifo must be linked on both sides, so a command is put in and passed to the other end (in this case nwserver) and it executes it.  So when I attempt to do nwservctl.sh stop, it goes till it this line:

echo "exit" | empty -s -o ./in.fifo



which should simply be putting the exit command into the fifo, which should then pass it to the nwserver process, telling it to exit.
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #6 on: November 09, 2010, 11:20:40 pm »


               nwnstartup.sh

Note: password and such obviously not right
[nwscript]
#!/bin/sh

cd /home/[nwndirectory here]

export LD_PRELOAD=./nwnx2.so

./nwserver \\\\
-publicserver 1 \\\\
-servername "My Server" \\\\
-dmpassword password \\\\
-oneparty 0 \\\\
-pvp 2 \\\\
-difficulty 2 \\\\
-elc 1 \\\\
-reloadwhenempty 0 \\\\
-module "My module" \\\\
-maxclients 70 \\\\
-servervault 0 \\\\
-maxlevel 40 \\\\
-gametype 7 \\\\
-autosaveinterval 0 \\\\
-playerpassword blblbl \\\\
-interactive \\\\
"$@"

[/nwscript]

Ignore the double slashes they are singles, nwscript and code both don't like them at the end of lines
               
               

               


                     Modifié par Calvinthesneak, 09 novembre 2010 - 11:22 .
                     
                  


            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #7 on: November 10, 2010, 12:37:38 am »


               autoreboot.sh
[nwscript]
#!/bin/bash
cd /home/nwnserver/nwn
./nwservctl.sh say -------------------------------------------
sleep 1
./nwservctl.sh say NOTE: SERVER WILL BE RESTARTING IN 30 MINS PLEASE SAVE AND BE READY
sleep 1
./nwservctl.sh say -------------------------------------------
sleep 600
./nwservctl.sh say -------------------------------------------
sleep 1
./nwservctl.sh say NOTE: SERVER WILL BE RESTARTING IN 20 MINS PLEASE SAVE AND BE READY
sleep 1
./nwservctl.sh say -------------------------------------------
sleep 600
./nwservctl.sh say -------------------------------------------
sleep 1
./nwservctl.sh say NOTE: SERVER WILL BE RESTARTING IN 10 MINS PLEASE SAVE AND BE READY
sleep 1
./nwservctl.sh say -------------------------------------------
sleep 300
./nwservctl.sh say -------------------------------------------
sleep 1
./nwservctl.sh say NOTE: SERVER WILL BE RESTARTING IN 5 MINS PLEASE SAVE AND BE READY
sleep 1
./nwservctl.sh say -------------------------------------------
sleep 240
./nwservctl.sh say -------------------------------------------
sleep 1
./nwservctl.sh say NOTE: SERVER WILL BE RESTARTING IN 1 MIN PLEASE SAVE AND LOG OFF NOW
sleep 1
./nwservctl.sh say -------------------------------------------
sleep 60
./nwservctl.sh restart
sleep 5
killall -9 Watchserver.sh
sleep 5
killall -9 inotifywait
sleep 5
./lock.sh
sleep 120
./nwservctl.sh playerpassword
sleep 125
./Watchserver.sh
exit
[/nwscript]
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #8 on: November 10, 2010, 07:51:39 am »


               Argh, I think my issue is with my mkfifo.  



If I manually create my in and out fifo files using:



mkfifo -m 771 ./in.fifo ./out.fifo it gets stuck.



If I don't create the files at all and allow the script to create them it seems to launch my server, but any further commands sent to the queue via the nwservctl.sh script cause a buffer overflow.
               
               

               
            

Legacy_Skildron

  • Sr. Member
  • ****
  • Posts: 421
  • Karma: +0/-0
Linux NWServer restart
« Reply #9 on: November 10, 2010, 10:36:14 am »


               After some thorough testing of the nwservctl.sh script and reading the man page of empty, I found out that you must not create the fifos beforehand.

From 'man empty':

An interface for the input and output data channels of the forked process is performed by two fifo files which  names  may  be  specified with  -i and -o keys. These files are automatically created/deleted any time you start/exit empty daemon, so you must not create them manually.

empty -f
will not work with precreated fifo files so nwserver never starts. I could not test with nwnx2 because I don't have it, but with plain nwserver, everything works and you can communicate with nwserver via the nwservctl.sh script. Bear in mind, though, that lots of server commands are set up in a way so that they don't give output on the console. I don't know wether nwserver would create output on those commands, but the script only catches output for status, help and listbans. All other commands stay silent, even if they normally would give output.

About correct passphrases for nwnx2, the variable in the script holds the value nwstartup.sh returns, and as soon as
empty -w
finds in in the out.fifo, it reports back successful server startup.

HTH
Greetings
Skildron
               
               

               


                     Modifié par Skildron, 10 novembre 2010 - 10:57 .
                     
                  


            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #10 on: November 10, 2010, 06:13:48 pm »


               Thanks Skil.



so this is what's happening....


./nwservctl.sh start
Starting nwserver please wait..
empty: Data stream is empty. Keyphrase wasn't found. Exit on timeout
nwserver is running now



So it's seemingly having an issue with removing the password.  What's more soon as I try any new command from another term window or a crontab command (such as executing the autoreboot.sh script) it blows up.




./nwservctl.sh stop
*** buffer overflow detected ***: empty terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x37)[0x7f83db432527]
/lib/libc.so.6(+0xfe3e0)[0x7f83db4313e0]
/lib/libc.so.6(__read_chk+0x22)[0x7f83db4318c2]
empty[0x402899]
/lib/libc.so.6(__libc_start_main+0xfe)[0x7f83db351d8e]
empty[0x4017e9]
======= Memory map: ========
00400000-00405000 r-xp 00000000 08:05 620939                             /usr/bin/empty
00604000-00605000 r--p 00004000 08:05 620939                             /usr/bin/empty
00605000-00606000 rw-p 00005000 08:05 620939                             /usr/bin/empty
00606000-00608000 rw-p 00000000 00:00 0
017f2000-01813000 rw-p 00000000 00:00 0                                  [heap]
7f83db11d000-7f83db132000 r-xp 00000000 08:05 352285                     /lib/libgcc_s.so.1
7f83db132000-7f83db331000 ---p 00015000 08:05 352285                     /lib/libgcc_s.so.1
7f83db331000-7f83db332000 r--p 00014000 08:05 352285                     /lib/libgcc_s.so.1
7f83db332000-7f83db333000 rw-p 00015000 08:05 352285                     /lib/libgcc_s.so.1
7f83db333000-7f83db4ad000 r-xp 00000000 08:05 155675                     /lib/libc-2.12.1.so
7f83db4ad000-7f83db6ac000 ---p 0017a000 08:05 155675                     /lib/libc-2.12.1.so
7f83db6ac000-7f83db6b0000 r--p 00179000 08:05 155675                     /lib/libc-2.12.1.so
7f83db6b0000-7f83db6b1000 rw-p 0017d000 08:05 155675                     /lib/libc-2.12.1.so
7f83db6b1000-7f83db6b6000 rw-p 00000000 00:00 0
7f83db6b6000-7f83db6b8000 r-xp 00000000 08:05 155694                     /lib/libutil-2.12.1.so
7f83db6b8000-7f83db8b7000 ---p 00002000 08:05 155694                     /lib/libutil-2.12.1.so
7f83db8b7000-7f83db8b8000 r--p 00001000 08:05 155694                     /lib/libutil-2.12.1.so
7f83db8b8000-7f83db8b9000 rw-p 00002000 08:05 155694                     /lib/libutil-2.12.1.so
7f83db8b9000-7f83db8d9000 r-xp 00000000 08:05 155672                     /lib/ld-2.12.1.so
7f83dbabb000-7f83dbabe000 rw-p 00000000 00:00 0
7f83dbad7000-7f83dbad9000 rw-p 00000000 00:00 0
7f83dbad9000-7f83dbada000 r--p 00020000 08:05 155672                     /lib/ld-2.12.1.so
7f83dbada000-7f83dbadb000 rw-p 00021000 08:05 155672                     /lib/ld-2.12.1.so
7f83dbadb000-7f83dbadc000 rw-p 00000000 00:00 0
7fff18975000-7fff18996000 rw-p 00000000 00:00 0                          [stack]
7fff189ff000-7fff18a00000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
./nwservctl.sh: line 59:  2217 Aborted                 $CATCH_OUTPUT

               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Linux NWServer restart
« Reply #11 on: November 10, 2010, 07:53:42 pm »


               ok problem solved. Buffer size in the nwservctl.sh was set to something larger than Linux will support.


Line 28 should be changed to the following:

CATCH_OUTPUT="empty -r -t 30 -b 8192 -i out.fifo" #8192 bytes is size of FIFO on linux



EDIT: Alternative for me is to rebuild a kernel with a larger buffer, but that's way over my head.
               
               

               


                     Modifié par Calvinthesneak, 10 novembre 2010 - 09:52 .