Perl: the Markov chain saw | |
PerlMonks |
Neverwinter Nights Server Restartby MrCromeDome (Deacon) |
on Jul 15, 2002 at 20:54 UTC ( [id://181916]=CUFP: print w/replies, xml ) | Need Help?? |
While I debated earlier over where to post this script, I ended up posting it in CUFP as opposed to the other places I discussed. Ironic, no? This probably isn't as cool as some of the other things here, but to the Unix and Perl dummies I work with, this is a blessing. What is it, you ask? A script to keep a game (read: Neverwinter Nights) running. Not that I'm particularly fond of this game, mind you, but it's something to pass the time. And with the regularity that the server part of the game crashes, it's been really hard to pass time playing it, until now. For those of you who are interested in the nitty gritty, this script works for Linux only and requires that the user be root (don't gripe, I know. . .) or that the user be granted permission to use /sbin/pidof (this can be accomplished by using sudo or something similar). 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. If you run this as a non-root user, you also may wish to have screen installed, otherwise you will have to have a terminal session constantly open to the Linux machine to ensure that the restart script keeps running. The script MUST be installed in the same directory as the nwserver file. The script is fairly well commented, and any things you might wish to change are clearly commented. Chances are, you will only have to/want to change the time to sleep and the path to your NWN installation. The script, as presented here, runs nwserver with no options. You may wish to change the following line: my $server = $path . "nwserver"; to something like this: my $server = $path . "nwserver -quiet -module Chapter2 -maxclients 16"; Alternatively, you can replace nwserver with a home-rolled shell script that starts nwserver with the options that you use (this is what I do). If you really want to be cool, you can redirect the output of this script to a file, so you have a nifty log of when your server crashed and when it was restarted: ./nwrestart > nwrestart.log & As always, I'd love constructive comments and criticisms on how to do things better. Can't learn unless you rip me apart.
Thanks, and have a great localtime() =)
Back to
Cool Uses for Perl
|
|