Terminating the server
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
-
- Posts: 69
- Joined: Wed Apr 22, 2009 5:32 pm
Terminating the server
Hey Folks!
Im searching for a way to shutdown the server (on windows) without loosing any data. Since I want to automate this ideally without using InGame commands and without using telnet. What I want to do is writing a script which checks if a player is online at night and if not it shuts down the server, swaps the server's JAR file with a newer one I uploaded before and restarts the server using this new JAR. The only problem I'm experienceing is shutting down the server automatically without modifing it, without InGame command, without telnet and without loosing any data.
The only way to perform a clean shutdown from outside seems to be pressing CTRL + C within the server's console.
There is a windows commandline tool called "taskkill" but the server seems to handle this signal incorrect (or does not even get it?) and shuts down imediatly without saving any data.
Does anyone have an idea how to get this working?
Im searching for a way to shutdown the server (on windows) without loosing any data. Since I want to automate this ideally without using InGame commands and without using telnet. What I want to do is writing a script which checks if a player is online at night and if not it shuts down the server, swaps the server's JAR file with a newer one I uploaded before and restarts the server using this new JAR. The only problem I'm experienceing is shutting down the server automatically without modifing it, without InGame command, without telnet and without loosing any data.
The only way to perform a clean shutdown from outside seems to be pressing CTRL + C within the server's console.
There is a windows commandline tool called "taskkill" but the server seems to handle this signal incorrect (or does not even get it?) and shuts down imediatly without saving any data.
Does anyone have an idea how to get this working?
-
- L2j Veteran
- Posts: 3437
- Joined: Wed Apr 30, 2008 8:53 am
- Location: Russia
Re: Terminating the server
Add telepathic module to the server, for reading admin's mind and shutdown.
Use global tasks for restart on schedule.
Use global tasks for restart on schedule.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
public static final int PI = 3.1415926535897932384626433832795;
- Notorious
- Posts: 501
- Joined: Thu May 28, 2009 3:50 pm
- Location: Sweden
Re: Terminating the server
Yeah, just use the global task for restarting server, and screw it if someone is online.
Then in the startGameServer.bat, add something similar to:
if exist c:\L2J\update\*.* copy /Y c:\L2J\update\*.* c:\L2J\libs
Modify this to fit your needs.
Then in the startGameServer.bat, add something similar to:
if exist c:\L2J\update\*.* copy /Y c:\L2J\update\*.* c:\L2J\libs
Modify this to fit your needs.
- janiii
- L2j Veteran
- Posts: 4269
- Joined: Wed May 28, 2008 3:15 pm
- Location: Slovakia
Re: Terminating the server
yeah, i had something similar. i renamed the new l2jserver.jar to l2jserver_new.jar and copied it to the gameserver directory where the server is running with l2jserver.jar. then when the server is starting, it checks if a l2jserver_new.jar is existing, copies the old l2jserver.jar to the backup directory and adds a timestamp to the name. then it renames the new l2jserver_new.jar to normal l2jserver.jar and loads the server. 
the script also does a database backup before starting the server and checks for an update script.

the script also does a database backup before starting the server and checks for an update script.
Code: Select all
@echo offtitle l2j gameserver console:startecho Backing up the gameserver DBset hh=%time:~0,2%if "%time:~0,1%"==" " set hh=0%time:~1,1%mysqldump -h localhost -u dbuser -pdbpwd l2db > backup/l2db_%date:~9,4%%date:~6,2%%date:~3,2%_%hh%%time:~3,2%%time:~6,2%.sqlif exist update.sql echo Updating databaseif exist update.sql mysql -h localhost -u dbuser -pdbpwd l2db < update.sqlif exist update.sql copy update.sql backup\update_%date:~9,4%%date:~6,2%%date:~3,2%_%hh%%time:~3,2%%time:~6,2%.sqlif exist update.sql del update.sql[b]if exist l2jserver_new.jar echo Loading a new l2jserver.jar[/b][b]if exist l2jserver_new.jar copy l2jserver.jar backup\l2jserver_%date:~9,4%%date:~6,2%%date:~3,2%_%hh%%time:~3,2%%time:~6,2%.jar[/b][b]if exist l2jserver_new.jar del l2jserver.jar[/b][b]if exist l2jserver_new.jar ren l2jserver_new.jar l2jserver.jar[/b]echo Starting L2J Game Server.echo.REM -------------------------------------REM Default parameters for a basic server.java -Djava.util.logging.manager=net.sf.l2j.util.L2LogManager -Xmx2048m -cp ./../libs2/*;l2jserver.jar net.sf.l2j.gameserver.GameServerREMREM If you have a big server and lots of memory, you could experiment for example withREM java -server -Xmx1536m -Xms1024m -Xmn512m -XX:PermSize=256m -XX:SurvivorRatio=8 -Xnoclassgc -XX:+AggressiveOptsREM If you are having troubles on server shutdown (saving data),REM add this to startup paramethers: -Djava.util.logging.manager=net.sf.l2j.L2LogManager. Example:REM java -Djava.util.logging.manager=net.sf.l2j.util.L2LogManager -Xmx1024m -cp ./../libs/*;l2jserver.jar net.sf.l2j.gameserver.GameServerREM -------------------------------------if ERRORLEVEL 2 goto restartif ERRORLEVEL 1 goto errorgoto end:restartecho.echo Admin Restart ...echo.goto start:errorecho.echo Server terminated abnormalyecho.:endecho.echo server terminatedecho.pause
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
-
- Posts: 69
- Joined: Wed Apr 22, 2009 5:32 pm
Re: Terminating the server
_DS_ wrote:Add telepathic module to the server, for reading admin's mind and shutdown.

I asked a simple question if the server can be shut down from outside. Normally you can send special messages to a process which tell him to shut down with(out) saving data. SIGTERM, SIGKILL, etc.
On a Windows machine this seems not to work with an L2J server and so I asked if this issue is related to a missing handler for those commands in the server or not. Because normally this IS possible. So please do not use offending language or just ask if you did not understand my question.
Writing a script which swaps the server and all this stuff is not the problem (anyway thank you, janiii, for sharing yours). The only problem is to perform a clean shutdown. Humm...global task...for that I have to modify the server to check if players are online, dont I? Are those global tasks loaded once on server startup or am I able to add new ones during runtime?
I would prefer not editing the server for this.
- janiii
- L2j Veteran
- Posts: 4269
- Joined: Wed May 28, 2008 3:15 pm
- Location: Slovakia
Re: Terminating the server
i can normaly make ctrl+c on the command window of the gameserver and it handles the shutdown command on server and makes normal shutdown with saving data.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
-
- L2j Veteran
- Posts: 3437
- Joined: Wed Apr 30, 2008 8:53 am
- Location: Russia
Re: Terminating the server
Use telnet for shutdown/restart, this is simple.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
public static final int PI = 3.1415926535897932384626433832795;
-
- Posts: 69
- Joined: Wed Apr 22, 2009 5:32 pm
Re: Terminating the server
Yes, (as I already saidjaniii wrote:i can normaly make ctrl+c on the command window of the gameserver and it handles the shutdown command on server and makes normal shutdown with saving data.

Ok, this may be an option if there is no other solution. But enabling telnet only to be able to shutdown the server seems not to be the optimal solution to me._DS_ wrote:Use telnet for shutdown/restart, this is simple.
- janiii
- L2j Veteran
- Posts: 4269
- Joined: Wed May 28, 2008 3:15 pm
- Location: Slovakia
Re: Terminating the server
make a jython script or a java class, that would trigger a restart. it is up to you how you want to make it. but you seem not want to do any coding, you seem not willing to enable telnet.. dont know how to help you if you dont want to do anything for your desired functionality..
but the best way is really an automatic scheduled restart, like on 4am. there are not many players online, and if, so they should wait 2-5 minutes for the server to be online again (they can go to the toilette in the mean time, they are glad for that restarts at night, really)
Code: Select all
seconds = 60restart = True Shutdown.getInstance().startTelnetShutdown("code triggered restart / shutdown", seconds, restart)
but the best way is really an automatic scheduled restart, like on 4am. there are not many players online, and if, so they should wait 2-5 minutes for the server to be online again (they can go to the toilette in the mean time, they are glad for that restarts at night, really)
Last edited by janiii on Tue Sep 08, 2009 1:33 pm, edited 1 time in total.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
- Notorious
- Posts: 501
- Joined: Thu May 28, 2009 3:50 pm
- Location: Sweden
Re: Terminating the server
Try with the command:
Don't know for sure if it shuts down properly, but atleast it doesn't say "Server terminated abnormaly".
Code: Select all
tskill java
- DrHouse
- L2j Inner Circle
- Posts: 912
- Joined: Mon Jan 22, 2007 12:14 am
- Location: Spain
Re: Terminating the server
Either if you exit your server using GM restart/shutdown or through a SIGTERM, data will be saved exactly in the sameway (check class Shutdown, it is an unique shutdown hook for all signals). However, if you send a SIGKILL (in windows termimate process), the process will stop and no data will be saved.

Leadership and management are not talk and talk, but talk and do
Proud of being a part of this project
-
- Posts: 69
- Joined: Wed Apr 22, 2009 5:32 pm
Re: Terminating the server
Without specifying option /F L2J shuts down immediately without saving any data. I was wondering if this may be a problem with L2J handling the appropriate signal. If not it seems to me that there is no solution to automatically shutdown the server from outsite. If this is the case I have to modify it. I was not willing to do any coding within the server if I was able to get this working another way.TASKKILL [/S system [/U username [/P [password]]]]
{ [/FI filter] [/PID processid | /IM imagename] } [/F] [/T]
Description:
This command line tool can be used to end one or more processes.
Processes can be killed by the process id or image name.
Parameter List:
[...]
/F Specifies to forcefully terminate
process(es).