Ultimate JKA Server Restarter (Linux) (4.00)

By Cthulhu99
Date: 07-12-2010
Version: 4.00

Download

Readme

********************************************************
Server starter/restarter and crash checker for Jedi Knight: Jedi Academy.

VERSION: 4.00
Platform: Linux
Game/MOD supported: ALL
********************************************************

################################################################################

Server start/restart description:

The script will launch an auto-generated script to the background, which contains the server command line to execute.
This script will maintain a recursive mode, and if the server is closed/killed, it will reopen the process instantly.
If this script is closed/killed, the main script will start it again after the script restart time.

Nmap check method description:

This script uses the open source Nmap software (http://www.nmap.org).
Nmap possesses several functions and features, but this script only uses its port mapping.
The check is made by Nmap mapping the server UDP port.
If the port responded with a accepted or refused, it means the server is either running normally and responding, or the process is not running.
If the port did not answer back, it means either a firewall is blocking that port or the process is not responding.
But since the script makes local checks and that port must be opened without firewall for players to connect,
the script will assume the process is not responding and kill it.
This method is recommended for those with root superuser privilege (Nmap UDP port mapping won't work without it), who wants an advanced port mapping.

PS check method description:

PS is a UNIX util with the function of listing processes, it's PID, and several other data.
This script uses a feature which check the state of a process.
Linuxjampded must always mantain a STATE Ss when responding properly, if a R STATE occurs, the process is not responding properly and thus will be killed.

As described by the ps manual.

S Interruptible sleep (waiting for an event to complete)
s is a session leader
R Running or runnable (on run queue)

This method is recommended for basically any user. It requires no privilege and has a very small resource usage.

Ncat check method description:

Version 4.00 added a new UDP check method using Ncat.
Ncat is a tool part of the Nmap project which allows you to connect to another port on several different protocols, or allows you to open that port for others to connect.
Ncat does not requires root superuser privilege.
The script however, will only use the connect-to feature of Ncat using the UDP protocol.
Ncat will attempt to connect to server and send a message.
If the server sends a reply, the server is responding normally.
If the server does not send a reply, the process is either not running or not responding.
After the ncat check is made, a check for the process status is made.
If the process does not exist, the process is not running.
If the process exists, the process is not responding and will be killed by the script.
Ncat check method is recommended for all those who wants a UDP check method and does not have root superuser privilege and/or wants minimal resource usage.

################################################################################

Dynamic Rotation description:

Dynamic Rotation is a way to make several different rotations in each day of the week, to a total of seven, or each month, to a total of twelve.
By using this method the server becomes a lot more dynamic, and can help in MODs where rotation is unstable and can crash the server, making it possible
for maps at the end of the rotation to be more played in other days/months if set to a upper layer.
Rotations for each day can be set on the drotation_day.cfg file, while rotations for each month can be set on the drotation_month.cfg file.
To enable the Dynamic Rotation feature, check the script.cfg file.

Version 4.00 includes a rehash feature, making it possible to update a Dynamic Rotation without needing to wait for another day or deleting the Dynamic Rotation auto-generated file.

OBS: It's highly recommended to remove the current rotation and its vstr from the server CFG.

################################################################################

HTML server status page generator description:

Version 4.00 includes a html generator to display information such as,
process status, Dynamic Rotation status, Dynamic Rotation for the day/month, server start/restart log, and server crash log.
After generating the html file, it can either be set to a local directory or send the file to a remote directory via FTP.
To enable this feature, check the script.cfg file.

################################################################################

CGI script description:

Version 4.00 includes a CGI script (bash+html) to be used with a web server.
The script will allow you to start/stop both the script and the server, and also check the server log, start/restart log and server crash log.

OBS: This script requires that CGI is enabled within your webserver.
OBS: Using a module such as suPHP/suExecPHP with Apache is highly recommended. Without it, Apache will execute the script/server on the same user running the web server.

NOTE: Setting a password on this script with the web server is highly recommended.

################################################################################

Updater description:

The updater can be set to autodownload patched scripts, and required files, or to only show the mirrors where the full
version can be download.
To enable/disable the autodownload feature, check the script.cfg file.
To run the updater, execute updater.

OBS: The updater was created in V3.00, thus any version below it is incompatible.

################################################################################

INSTALL:

1) Unpack the file linuxjascriptv400.tar.gz to any folder. (tar -xzvf linuxjascriptv400.tar.gz)
1a) Install Nmap (http://www.nmap.org), if you plan on using the Nmap check method.
2) Check script.cfg and configure it. (All lines are described for what you need to set.)
2a) Check drotation_day.cfg or drotation_month.cfg and configure it if you have Dynamic Rotation enabled.
3) Now you have the option of either running it on crontab (for box reboot/shutdown purpose) or running without it.
3a) For crontab, add the following line to your user crontab table, in this case an one minute check (crontab -e. Remember, if you are using Nmap you
must put the script in the root table): */1 * * * * /"dir"/jkascript nohup
3b) Without crontab, execute ./jkascript and check the options.
3c) Check cgi-bin/jkascript.cgi, configure it, and put it in your cgi web folder if you plan on using the CGI script.

OBS: Do not forget to give execute permission (chmod +x) to jkascript and all .sh scripts.

################################################################################

ERROR CODES:

Error codes were added for better debugging within the script.
Each error code is related to a specific script only.

LIST:

ERROR CODE / SCRIPT

1 / master.sh (Master script)
2 / ccheck.sh (Server status check script)
3 / drotation.sh (Dynamic Rotation script)
4 / html.sh (HTML server status generator script)

################################################################################

Changes from V1 to V2:

Added a single configuration file, you no longer have to check all the scripts.
Added comments in all areas for easy understanding.
Added the option of changing between NMap (UDP) and PS (process) check methods.

Changes from V2 to V3.00:

Support for all versions added.
Most lines have been either cleaned or optimized, error check for wrong values also has been added.
Dynamic Rotation added.
Updater added.

Changes from V3.00 to V3.01:

The code has been further cleaned and optimized.
All error checks with the exception of autodownload and server.cfg, have been migrated to the master script.
All error checks have been improved.
Added some echo messages for better interpretation in the stdout.
Added a start/stop script.

Changes from V3.01 to V3.02:

Fixed a bug added by V3.01 preventing the use of NMap check method.
Check for directory, user, id, and method user limitation check errors added to the master script.
CFG files are now stored at the cfg folder, while previous version files after auto update are stored in the old folder.
Code for the updater has been further improved.

Changes from V3.02 to V3.03:

Moved the variables for process status check (running or not running), crash checker status (running or not running), and Dynamic Rotation script status (running or not running), to the correct place to avoid misinformation within the script.
Changed variable pid to pidc within ccheck.sh, and variable pid to pidr within drotation.sh, for better code organization.

Changes from V3.03 to V4.00:

Log server feature added.
A recursive bash script was added to replace the time based server status check (running/not running).
Ncat check method added.
Dynamic Rotation monthly type added.
Dynamic Rotation map limit per rotation is now unlimited.
Added Dynamic Rotation rehash feature.
Dynamic Rotation is no longer stored with the server CFG. Instead a exec line is added, and the rotation is stored with an auto-generated file.
HTML server status page generator added.
CGI Script added.
Pid files have been added. script.pid for the script, and serverstarter.pid for the recursive script running the server.
Filesdir variable was removed. A new variable (scriptdir) has been added to check for the script directory automatically.
User variable was removed. The user is now checked automatically in the script.
User variable to run the JKA server in the Nmap check method has been added.
Added options nohup and killserver in the jkascript script.
Added a Nmap path variable.
Error checks have been greatly improved and spread out through the entire code.
Error and exit codes have been added.
The entire code was re-checked, re-written, further improved and optimized for performance.
Updater has been further improved.

################################################################################

FAQ:

Q: Will you be releasing another version(s)?
A: Probably not. I have pushed this script far enough, and i don't have the same interest that i had before.

Q: I want to report a bug/feedback, or i need help, how can i contact you?
A: Via forum http://forums.moviebattles.com/showthread.php?t=32016 or via email yog.sothoth99@gmail.com.

Q: Which language did you use to code this script?
A: Scripts were coded in bash scripting, CGI script was coded in bash+html.

Q: Why this version does not contain separate restart time for each feature?
A: Main reason is to avoid overflow, but it's also to avoid executing several functions at the same time and breaking each other.

Q: Can i edit your script?
A: For personnal use, yes, for distribution, no. By distributing a version not made by me, a version hell will probably exist,
and the updater will be useless. If you have suggestions, contact me.

Q: Can i use your script on my mod?
A: Yes, as long as nothing is changed.

Q: Are you accepting donations?
A: Of course not. If you want to donate, donate to those who made this script possible at http://www.nmap.org.

################################################################################

Thanks to: (People who helped me at some point)

eXploit
=Someone=
Necrom
Kaynehril
TK-231
AceVentura
Lervish
*NSOQ*Lagawan 1.0
*NSOQ*Wolfman
*NSOQ*Helter Skelter
[CR]QuetzalCoalt
[CR]Tipo

-------------------------------------------------------------

* Cthulhu@GBITnet.com.br / 2010 ©