Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Neverwinter Nights Server Restart

by MrCromeDome (Deacon)
on Jul 15, 2002 at 22:08 UTC ( [id://181940]=note: print w/replies, xml ) Need Help??


in reply to Re: Neverwinter Nights Server Restart
in thread Neverwinter Nights Server Restart

At the risk of going a bit too far OT here:

The above script has already been submitted to the BioWare community. I hope it's making the rounds already.

The next project involves a web based server administration interface in Perl. Like you said. . . lots of Perl work waiting in NWN ;) Until the content creation tools (and server stability issues) get resolved, I'm going to stick to writing Perl utilities to help manage the game better.

Thanks for your interest =) I'd be interested in chatting more about this with you. /msg me again sometime =)

MrCromeDome

  • Comment on Re: Re: Neverwinter Nights Server Restart

Replies are listed 'Best First'.
Rewritten Neverwinter Nights Server Restart
by Anonymous Monk on Dec 17, 2002 at 16:38 UTC
    *************************************** [root@never nwn]# more nwstart-ebro.pl #!/usr/bin/perl $nwpath="/usr/local/nwn"; #if [ -z $1 ]; then # echo "you did not give me a module to launch." # echo "usage: $0 MODULENAME" # exit #ifi #MODULE=$1 #while(1){} $pid_file = $nwpath . "/.nwnpid"; unless(open (PIDS, "<$pid_file")){ print "Informational: no pidfile found at $pid_file\n"; system("cd $nwpath"); system("./nwserver -module Yourmod -maxclients 60 -min +level 1 -maxlevel 20 -pauseandplay 0 -pvp 2 -servervault 0 -elc 0 -ilr 0 -gam +etype role play -oneparty 0 -difficulty 3 -autosaveinterval 0 -playerpassword you +rpass -dmp assword fryme -servername yourserver -publicserver 0 -reloadwhenempty +0 -qui et &"); } while (<PIDS>) { chomp; $line=$_; print "pid line is: $line\n"; if ($line eq "0"){ print "nwn may have failed to start up earlier, trying + again...\ n"; } if ($line ne "0") { $arg=$ARGV[0]; if ($arg eq "-f"){ #`rm -f $pid_file`; system("cd $nwpath"); system("./nwserver -module Yourmod -maxclients + 60 -minlevel 1 -maxlevel 20 -pauseandplay 0 -pvp 2 -servervault 0 -elc 0 -ilr 0 -gam +etype role play -oneparty 0 -difficulty 3 -autosaveinterval 0 -playerpassword you +rpass -dmp assword fryme -servername yourserver -publicserver 0 -reloadwhenempty +0 -qui et &"); }else{ print "nwn is already running! PID=$line\n"; } } else{ `cd $nwpath`; $output=`./nwserver -module Yourmod -maxclients 60 -mi +nlevel 1 -maxlevel 20 -pauseandplay 0 -pvp 2 -servervault 0 -elc 0 -ilr 0 -gam +etype role play -oneparty 0 -difficulty 3 -autosaveinterval 0 -playerpassword you +rpass -dmp assword fryme -servername yourserver -publicserver 0 -reloadwhenempty +0 -qui et &`; print "$output\n"; } } close PIDS; *************************************** [root@never nwn]# more nwkeepon-ebro.pl #!/usr/bin/perl # http://www.perlmonks.org/index.pl?node_id=181916 # The script looks at a file created by nwserver that # contains the PID of the server process. The list of # PIDs (well, the last in the list) from the system # is checked against the PID in the file, and if there # is no match, the server is assumed to be crashed, and # we attempt to start it again. # This calls nwstart.sh, but that script, too, seems a # bit faulty, as does nwstop.pl; they both give errors # unless the server is in just the right state. use strict; use warnings; # Path to your Neverwinter Nights installation: my $path = "/usr/local/nwn/"; # Don't change these two lines! my $pid_file = $path . ".nwnpid"; my $startpid = "nwstart"; my $server = $path . "./nwstart-ebro.pl -f &"; # Time to wait (in seconds) before checking to see if the server is st +ill alive: my $delay = 30; #my $pid = `cat $pid_file`; #my $pid_list = ""; #my $start_list = ""; while(1) { my $status=open (PIDS, "<$pid_file"); if (!$status){ print "no pid file found, server was previously stoppe +d graceful ly, no action required\n"; } else{ # Get the list of PIDs from Unix # check to see if the start script is already running... my $start_list = ` ps -ewf | grep nwstart | grep -v grep `; #print "start list is $start_list\n"; if ($start_list=~$startpid){ print "Start script is currently running, no action required\n +"; } else{ # Get the PID of the server my $pid = `cat $pid_file`; chomp($pid); # Get the list of PIDs from Unix #my $pid_list = `ps -ef | grep nwserver | grep -v grep | cut -d" " +-f6`; my $pid_list=`ps -eo "%c %p" | grep $pid | cut -d" " -f2-`; chomp($pid_list); # print "debug:pidlist: $pid_list\n"; # Get the lowest PID in the list $pid_list = substr($pid_list,rindex($pid_list," ") + 1,length($pid_ +list) - rindex($pid_list, " ")); # print "debug:pidlist:formatted: $pid_list\n"; # If two aren't equal, restart server if(($pid ne $pid_list) ) { if ($pid eq "0"){ print "PID is set to zero please check server and star +t manually \n"; }else{ print "pids do not match: pid: $pid pidlist: $pid_list\n"; my $now = localtime(); print "Restarting server. . . "; system("$server > /dev/null"); print "done (", $now, ")\n"; }}else{ print "server alive, going to sleep for $delay seconds\n"; print "pid: $pid pidlist: $pid_list\n"; } } } close PIDS; # Go to sleep and try again later sleep($delay); } ****************************************** root@never nwn]# more nwstop-ebro.pl #!/usr/bin/perl # Path to your Neverwinter Nights installation: $path = "/usr/local/nwn/"; $pid_file = $path . ".nwnpid"; open (PIDS, "$pid_file") or die "nwn is not running or there is no pid +file at $p id_file\n"; while (<PIDS>) { chomp; if ($_ ne "0") { print "Killing pid $_\n"; system("kill", "-9", "$_"); } } #$pid = `cat $pid_file`; #chomp($pid); #print "my pid was $pid\n"; #print "my pid_file was $pid_file\n"; #system("kill", "-9", "$pid"); system("rm", "$pid_file");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found