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 
 
Linux shell script

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



Joined: 25 Jul 2010
Posts: 13

PostPosted: Wed Jul 28, 2010 5:50    Post subject: Linux shell script Reply with quote

Hi,

I am really new to both linux and mysql but I have managed to get nwnx2 up and running correctly. Now one of the features I would like to do is the watchdog. However, I have been reading that the watchdog requires a shell script, which I believe you can download from the documentation for installing nwnx2 for linux.

I know this isn't a linux training forum, however, my brain is about fried and I really just want to get the server auto restarting and have nwnx2 running the show so I can learn how to do all the fun stuff with mysql. I was hoping someone could take the time to explain to me how to operate the shell scripts or at least point me somewhere that is a decent place that explains it well.

I appreciate any time you guys have to spend.

Thx ,

Mal
Back to top
View user's profile Send private message
Paul R



Joined: 17 Apr 2009
Posts: 42

PostPosted: Wed Jul 28, 2010 15:08    Post subject: Reply with quote

Hi, I guess it depends on what you mean by a watchdog kind of process really. A few examples have been posted on here already but I'll go through the details of a couple of different options and considerations.

Watchdog wrapper

One method is to wrap the startup script you had in the other post with a loop that will just keep running forever, for instance this in a bash shell:

Code:
#!/bin/bash
#
# Start the nwstartup script
#

cd /usr/local/nwn/

while [ 1 ]
 do
  echo "Starting NWN..."
  ./nwstartup.sh
 done


As the call to the nwstartup.sh script blocks till the nwserver process dies this will wait and when that instance stops and control is passed back to this script, either because you have purposefully stopped it either by killing the process or the nwnx_system plugin Reset() function another will be started immediately.

You can also do something after the shutdown of one nwserver process and the start of another such as archive the log files to somewhere else, this would take place after the ./nwserver.sh line and before the done.

Code:
#!/bin/bash
#
# Start the nwstartup script and archive the log files
#

cd /usr/local/nwn/

while [ 1 ]
 do
  echo "Starting NWN..."
  ./nwstartup.sh

  tar cvfj backup/logs_$(date +"%Y%m%d%H%M%S").tar.bz2 logs.0/*
  rm logs.0/*

 done


This will keep a date/time stamped archive copy of all of the files from the logs.0 subdirectory and place them in the another subdirectory called backup (this does not exist by default) and then remove the files. I've made the assumption that you don't have anything else in that logs.0 directory that you want to keep also be aware this will introduce a delay between the shutdown of one instance of the nwserver process and the start of the next while the logs are dealt with.

There are quicker ways to deal with the logfiles such as using the mv command to cycle through a rotating set of directory names (an example ad been posted on here before), this has the benefit of that a mv is pretty much instantaneous if keeping within the same filesystem as the base inode details are altered rather than an actual file copy taking place you could then archive them at your leisure or combine both of these methods to move the files to a temp directory and then archive them as a background task.

Dynamic Linker errors

You may think you can add those into the nwstartup.sh script but not quite how you have it at the moment, because you are exporting the LD_PRELOAD environment variable (so nwnx is used) any other non shell builtin commands used in that script will also try and use nwnx, which although it isn't really an issue can be confusing and a waste of time (you could stop this if you want by just setting the environment variable to the command itself by removing the export keyword and appending the whole ./nwserver command after the variable.

Code:
LD_PRELOAD=./nwnx2.so ./nwserver -blah -blah -blah


Probably best to keep them separate though.

Startup/Shutdown

If you do add a script like this then one thing to consider is the machine startup and shutdown. If the distribution you are using uses the init style scripts where you have a control script that will start and stop your NWN related script in the /etc/init.d/ directory and links to this in the runlevel directories (typically /etc/rc?.d/) you can then have the NWN server process start automatically after MYSQL server has started and also run a the appropriate time on shutdown to kill the watchdog process itself and the nwserver process nicely so you don't end up with it trying to start multiple times when shutting the machine down.

Those are slightly more complicated and I'm not sure if they have been described on this forum, if not let me know and I can post up what we use.


I've probably waffled on too much and missed the point of what you asked Embarassed have a search and a look through the docs, quite a bit of excellent information has already been given before.
_________________
oops
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Thu Jul 29, 2010 0:24    Post subject: Reply with quote

Thanks alot Paul for taking the time to help. In the time since the last post I have been reading alot about linux and shell scripts so I actually think I understood some of the things you were saying (I will be coming back to this post until I can fully grasp what you are saying.)

About the archiving of the log.0. I am assuming this would be necessary because the logs.0 are overwritten instead of appended everytime the server is restarted?

As a total noob, I am finding the most difficult thing is to know what to ask and and how to search for things on a technical forum like this when your technical knowledge on the subject is so small. But, I will keep digging and learning.

Thanks,

Mal
Back to top
View user's profile Send private message
Paul R



Joined: 17 Apr 2009
Posts: 42

PostPosted: Thu Jul 29, 2010 19:40    Post subject: Reply with quote

No problem, ask away Smile

About the archiving, yes some will be overwritten when the process is restarted. The main nwserverLog1.txt file will be appended to ... and it will be huge after a time depending on what you are logging. There is also a problem of the logfile being kept open by the process, which basically means if the file is open all the time you can't quite get rid of it to archive it off because although you might delete the file itself it may be held in memory and not actually released until the process dies so you don't claim any diskspace back.

I can't remember off hand if this happens with the nwserver process but it's good practise to shuffle them off when you can, it also keeps things neat and tidy if you want to look at a particular instance that was run.

As a beginner with any UNIX style platform I'd suggest using the man pages and there are also several good forums, if you haven't used them before the man pages are the usage documentation manual that are stored locally (along with some more comprehensive documentation under /usr/share/doc/). Such as this snippet:

Code:
$ man tar

TAR(1)                    BSD General Commands Manual                   TAR(1)

NAME
     tar — The GNU version of the tar archiving utility

SYNOPSIS
     tar [-] A --catenate --concatenate | c --create | d --diff --compare |
         --delete | r --append | t --list | --test-label | u --update | x
         --extract --get [options] [pathname ...]

DESCRIPTION
     Tar stores and extracts files from a tape or disk archive.

     The first argument to tar should be a function; either one of the letters
     Acdrtux, or one of the long function names.  A function letter need not
     be prefixed with ``-'', and may be combined with other single-letter
     options.  A long function name must be prefixed with --.  Some options
     take a parameter; with the single-letter form these must be given as sep‐
     arate arguments.  With the long form, they may be given by appending
     =value to the option.

FUNCTION LETTERS
     Main operation mode:


For more nwnx related things apart from actually installing MySQL and getting that started automatically, some housekeeping routines and updating nwnx when some new snazzy function comes out there isn't much to it ... unless you want to add some other background scripts like parsing the logfile for certain lines, updating webpages with logons and other events etc ... Wink
_________________
oops
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