logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Running NWNx using command line/screen

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support
View previous topic :: View next topic  
Author Message
Zarathustra217



Joined: 15 Aug 2011
Posts: 5

PostPosted: Mon Aug 15, 2011 13:40    Post subject: Running NWNx using command line/screen Reply with quote

Hi all,

We are planning to implement NWNx on our server (late decision, I know!). I've run in to a minor issue however - likely induced by my very meager ability with linux - that I'm hoping you would help me with. I've searched the forums for an answer but to no avail, but please bear with me if it has been asked before.

What I'm looking to do is to run NWNx through a regular shell script, since we already have a process watchdog in place that we intend to continue utilizing if possible. Since our watchdog also handles running server updates (our module filename changes accordingly), we however need to be able to handle command line options dynamically. So my first question is simply:

Would it work to edit the nwnstartup.sh script and replace the:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

./nwserver \
   -publicserver 1 \
   -servername YourServerHere \
   -dmpassword yourpw \
   -oneparty 0 \
   -pvp 0 \
   -difficulty 2 \
   -elc 1 \
   -reloadwhenempty 0 \
   -module "YourModuleHere" \
   -maxclients 32 \
   -servervault 1 \
   -maxlevel 40 \
   -gametype 0 \
   -autosaveinterval 0 \
   "$@"


with just:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

./nwserver $@


So that we pass all the command line options to our calling of the nwnstartup.sh script in our own shell script.

... and is there a reason it's "$@" and not $@ in nwnstartup.sh?

Second, is it possible to edit the nwnstartup.sh script to run through a screen so it becomes:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

screen ./nwserver $@


All help would be very much appreciated. I know some of it is related more to how linux work rather than NWNx, but I hope you can bear with me on that too.
Back to top
View user's profile Send private message
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Mon Aug 15, 2011 23:48    Post subject: Reply with quote

Yah, I prefer to put that info in the ini files too.

The '$@' in delimiters of some type because of how something works. Also you'd want to do your log handling there or well somewhere. They add up fast. Also consider acaos' netoverride, fewer crash bugs, the better.

Otherwise, we just run something like
Code:
while [ true ]; do ./nwnstartup.sh; sleep 5; done

in a screen session. Server name you might want to pass into the nwserver call, I think there's situations where it won't take properly from ini.

So anyway, I'm not sure you can invoke screen that way. You can mess with some script like echo $@; echo '$@'; and feed it some flags and see what happens.
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
Paul R



Joined: 17 Apr 2009
Posts: 42

PostPosted: Thu Aug 18, 2011 0:07    Post subject: Re: Running NWNx using command line/screen Reply with quote

Zarathustra217 wrote:
Would it work to edit the nwnstartup.sh script and replace the:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

./nwserver \
   -publicserver 1 \
   -servername YourServerHere \
   -dmpassword yourpw \
   -oneparty 0 \
   -pvp 0 \
   -difficulty 2 \
   -elc 1 \
   -reloadwhenempty 0 \
   -module "YourModuleHere" \
   -maxclients 32 \
   -servervault 1 \
   -maxlevel 40 \
   -gametype 0 \
   -autosaveinterval 0 \
   "$@"


with just:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

./nwserver $@


So that we pass all the command line options to our calling of the nwnstartup.sh script in our own shell script.

... and is there a reason it's "$@" and not $@ in nwnstartup.sh?



Yes you can and you may need to keep that as having double quotes around the variable, it affects the arguments as they are expanded out and if the quotes you supply around the arguments are also quoted.

This is from the bash man page and explains the difference between the $@ and $* shell variables and what happens if you quote them in the script.

Code:
       *      Expands  to  the  positional  parameters,  starting  from  one.  When the expansion occurs within double
              quotes, it expands to a single word with the value of each parameter separated by the first character of
              the IFS special variable.  That is, "$*" is equivalent to "$1c$2c...", where c is the first character of
              the value of the IFS variable.  If IFS is unset, the parameters are separated  by  spaces.   If  IFS  is
              null, the parameters are joined without intervening separators.

       @      Expands  to  the  positional  parameters,  starting  from  one.  When the expansion occurs within double
              quotes, each parameter expands to a separate word.  That is, "$@" is equivalent to "$1" "$2" ...  If the
              double-quoted  expansion  occurs  within a word, the expansion of the first parameter is joined with the
              beginning part of the original word, and the expansion of the last parameter is  joined  with  the  last
              part  of  the  original  word.   When  there are no positional parameters, "$@" and $@ expand to nothing
              (i.e., they are removed).



Quote:
Second, is it possible to edit the nwnstartup.sh script to run through a screen so it becomes:

Code:
#!/bin/sh

export LD_PRELOAD=./nwnx2.so

screen ./nwserver $@




You can use screen but you will need to use some more options to it, it's not something I use personally but there are some posts on here with some examples. You will get an error if you export the LD_PRELOAD var as you have it there because it will affect every external command after it has been set, in other words when the screen command is executed the dynamic linker will now try and attach the nwnx2 shared library to that process as well which at best is not going to work.

So as Lokey mentions you may need to execute the script as screen session rather than using screen in the script.


As you said you were new to Linux I just want to check you know what it is for and actually need to use it as it can complicate things slightly Smile

The screen command executes the command as a separate process in the background in something a bit like a virtual terminal, you can connect to the the input and output streams later on using another screen command so you can use the nwserver console commands like "say".

Paul
_________________
oops
Back to top
View user's profile Send private message
Zarathustra217



Joined: 15 Aug 2011
Posts: 5

PostPosted: Thu Aug 18, 2011 9:14    Post subject: Reply with quote

Thanks a lot for the help, both.

What we ended up doing was running the nwnstartup.sh script in a screen rather than using screen within it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group