How to reliably deploy a game server jar to a machine? - java

Well i have a game server now up and running on my local development machine but i want to deploy it to a real servermachine. The easiest way would be to just transfer the jar file to the server and run it with java -jar server.jar.
But i want to reliably deploy this jar to a server and keep it running like a daemon. The above command terminates if the server.jar crashes or it runs out of memory but i does not restart the server.
Second i want it to be deployable to multiple physical servers. So the server.jar is startet on many physical machines and keep running as daemons.
I thought about running the server inside a servlet in Java EE but i think that would not work because Java EE requires you application does not create a socket by itself. And because i use kryonet as a networking library i cant prevent my app from doing it/i have no idea how to overcome that issue.
Is there any way i can do what i wanted to do? Maybe any application suggestions or frameworks build for this task?
Thank you

In general, because I'm not that familiar with java, the easiest way would be to handle ur problem by the OS of the server. As an example if ur application tends to crash at some point, u could watch with the OS a task, and if the task crashed simply start it again.
The next step would be to code ur own "launcher" which does basically the same as the os, but in a more controlled way.
To ur second question, honestly i do not understand what u mean. Every application can be fired up multiple times. So on 1 physical machine having more of ur servers running would be no problem (2 ways u deal with port allocation or u distribute a config file). If u want to deploy ur server on many physical machines where should occur any problem? Sr i don't udnerstand this question.
In general to deploy a server, u need a install aka readme for the admins, and it should only contain dependencies, ur not allowed to distribute and one or more settings files to configure ur server. Also u can put in *.sh script to launch ur server.jar with the correct settings, or a *.bat for windows. If u have a launcher keep in mind it should be 100% setting dependent, so admins can control everything.
That's it for general. Sr if this was not java specific, but honestly i do not know if such a subject can even be language specific. It's too basic for this.

Related

Is it possible to automatically upload files when created to a web server?

I am working on a project using a Raspberry Pi and a web cam to detect motion.
I have got it to a stage whereby it takes an image and saves it on my computer. What I am wondering is, is it possible to let FileZilla automatically upload the image to my webserver when a new image is taken? Or is there any other ways that I could achieve this?
Since the post is tagged java, I'm assuming that you're using a Java program already or have the basic knowledge to create a Java program.
On to the answer: yes, you basically have two options.
1. Upload from within the Java program. FTP is probably the easiest since most web servers will have an FTP server running. Here is a tutorial you can use: http://www.codejava.net/java-se/networking/ftp/java-ftp-file-upload-tutorial-and-example
2. Use another utility outside your Java program to upload the file to your webserver. rsync would be the tool of my choice (tutorial here). When on a Linux machine (for example, the Pi) or a Mac, you can run a script that syncs the content of a local folder to a remote folder every x seconds:
while true; do <rsync command hier> sleep 5s; done
Note that that sleep period shouldn't be too short or you'll end up running multiple instances of rsync.
When on a Windows machine, you need to find another way to run a periodic process to trigger the rsync.

Preventing Java from creating new processes

I am setting up a little service to allow people to run temporary Minecraft servers on a spare box that's not being put to much use.
The .jar that will start up the Minecraft server will be uneditable, as in they can't upload a new .jar and run that in its place. However, the .jar will be the Bukkit Mod/Wrapper for Minecraft servers, which allows the loading of plugins that are in the form of .jars. What's stopping someone from creating their own plugin and using it to spawn more servers?
How can I prevent someone from using a server plugin to create another server process? I am already planning to make it so that each server will be ran under it's own user account, which wont be accessible to login from.
I'm not familiar with the Minecraft code base.
However you should look into running the code with a SecurityManager. This will enable you restrict many operations (such as being able to exec a new process).
Done correctly, this should enable you to completely lock down the loaded .jar file. It's possible that the Minecraft server does this for you already, it's a fairly obvious thing to want to restrict the activities of downloadable mods.
In linux there is a file called /etc/security/limits.conf.
Read this: http://linux.die.net/man/5/limits.conf.
nproc would limit the number of processes for the user/domain.

checking if windows update or any installer instace is running before starting my installer( java)

want to make a check in my installer before starting installation if any other installation is running beforehand. Like I want to make a check if windows update or any other installer is running i'll not start my installer.
I'm planning to check if any msiexec instance is running before hand. Is there any better approach, and will that be same for checking windows update. FYI my installer is in java
You should know that msiexec.exe will still be running for a couple of minutes after an installation is finished. This is a default behavior in the OS, it keeps the process alive for a couple of minutes, in case the user will start another installation, to save time from starting it all over again. So checking for the process could give you incorrect data.
Also, if you have your installer written in Java can you please explain why do you need to check for msiexec.exe processes?
Since your installer is in Java, I see no reason to check whether other installers are running, moreover there's no robust way to do so.
Does your installer try to replace system files? It should not.
Does your installer try to update a file in use? It must do it gracefully. And ask user to close an offending application; if it's not possible or user does not want to close the application right away, your installer asks user to restart the system when it completed installation.
Too much to care about, without other installers running. That's why it's wiser to use a specialized installer tool.
To check the OS for installations in progress you can use the following registry entry:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\InProgress
Please note that Windows Installer does not allow multiple InstallExecuteSequences to be executed simultaneously, however you can launch multiple installation UIs from different packages. The package enters InstallExecuteSequence usually at the moment you press "Install" and grant all the permissions for starting the system changes (creating registry, copying files, etc...).
Here you can find more information about InstallUISequence and InstallExecuteSequence:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa372404(v=vs.85).aspx
Thank u guys for your suggestions, I final decided to go with creating a windows native dll to check the status of WindowsInstaller. The Windows Installer service is currently running if the value of the dwControlsAccepted member of the returned SERVICE_STATUS_PROCESS structure is SERVICE_ACCEPT_SHUTDOWN. Then used JNI to to call it from my java class.

Running Java UI program though unix

I want to facilate my client to run java program through UNIX command prompt using some shells. It'll look more effecient if they would be able to give input through some GUI. So it can be tested immedietely. I dont want prefer unix commands fro input.
Can somebody tell me how to run Java swing or applet programs in UNIX?
As Thompson mentioned, looking at Java Web Start could be a good idea.
Otherwise, if what you want is to execute, using a *NIX-like terminal, an application located on a remote host and have it rendered on your local display, then you need to do a few things:
you need a working X server on the local machine
you need to export the DISPLAY to the local machine (you can do this by setting up the DISPLAY environment variable on the remote system)
then you need to start your Java app from the command-line.
Hope this helps.
Here's an example of how to export your display over SSH.
Java programs use the X windows system (just like any other GUI on Unix). Assuming your X windows system is setup correctly, you should just open up a JFrame and do your GUI coding just like Windows.
Using the command prompt to launch a GUI is so last millennium. If you can distribute from a server, look into Java Web Start to provide the end-user with a simple and painless install.
Oh, and of course, follow Starkey's advice to throw a JFrame into the mix.
If you have an X-server installed locally, Putty can tunnel the X11-graphics generated by Linux Java back from the server to your local machine, and view it there.
If the above doesn't make sense to you, your next best bet is either running the Java code locally with Java Web Start (and code it to communicate back to the remote server) or run Servlets inside a Java Web Server running on the remote host.
In other words, GUI over a Putty connection is not something which is easily done.

Detecting/controlling a process

I have a java application where I want to check to see if an application is running. If it is not running, I want to start it. If it is running, I want to kill it and then restart it.
Can someone tell me how to do this? I can start/stop the program easily enough, with the ProcessBuilder. But I cannot detect a process that is already running.
Thanks for your help!
John
Without the cooperation of the application (ideally have it listening on a network port), that may be impossible (your Java app might not have the rights to kill the app) and requires OS-specific code. On Linux, you'd uase the ps and kill commands.
Might sound silly, but you can create a file with a known name on application startup. Doesn't need to contain anything. To check if your application is running, check if that file exists.
Is the other application (the process you are monitoring) under your responsibility? If so, you can use a method I used in some high-availability system a few years back:
Open a connection to that other application and "ping" it. If the other application does not respond within a given timeout, it is either down or "hung", which is as bad (and something you can't detect through process monitoring.
Opening a connection can be done using sockets, or though more sophisticated protocols (SOAP?).
An alternative is to have the application send a "I'm alive" message every so often. If you haven't received it in some time - your application needs restarting.
In order to actually "kill" the other process, you can keep the Process instance you get from the exec() method, and destroy() it when you so choose.
Thanks for the replies. That was what I was afraid off. We are trying NOT to add more things to the application that I want to start up. We are basically trying to add a remote control web interface to a collection of applications.
The web server application that I am writing would basically start/stop 3 apps that all talk to each other to achieve a goal. If my web server starts and stops them, all is well. But if, for some reason they are already running when I try to start them bad things happen.
It is something I know I could handle with Visual Studio (C++/C#/etc). But this project has to be written in java due to a platform independence requirement.
Thanks for your help everyone!

Categories