How to stop the application from within in Openshift - java

I want to be able to stop my application from inside every 3 days. I just want to schedule a method that would automatically stop the application without any intervention from outside (like sitting on my desktop etc).
So far, I have these in mind:
Runtime.getRuntime().exec("rhc stop-app --app ApplicationName"); //This doesn't work. I have tried it
Or
System.exit(0) // I am told to not run this command on openshift server
Or
Runtime.getRuntime().exit(0) //I am afraid to run this command
Or
Runtime.getRuntime().halt(0) //I am afraid to run this command as well
Some of those commands I am afraid to use because I am told to not run them on openshift server as they may actually stop the whole vm. And that will stop all the applications that are hosted on that vm. And that will get me banned. I will get banned.
edit: This question is not how to stop an application generally. This question is regarding how to stop a Spring MVC wep application which is hosted on OpenShift server. And no those answers donot work in that link.

Well, I just used Runtime.getRuntime().exit(0) and it successfully stopped my application. I didn't get ban or anything. And I restarted my application to see if there are any issues. No Issues. So that command will do. Thanks
edit: This works but openshift restarts the application automatically. So this is not the answer. I will put the answer here if I find one. Thanks

Related

Java Play Framework: "No java installations was detected."

I've inherited and am maintaining a scala/play app that was built several years ago (2014). Every night there's a cron job executing a shell script to restart the app. Running this script from the command line at any time works just fine as well. The app stops, cleans up, rebuilds then restarts.
I've been asked to build a php page which will allow this same shell script to be run via php. I thought it would be very straightforward, but when I exec() the same shell script, I get the output message, ""No java installations was detected."
But of course it is there, where the variables say it should be.
I've tried cd'ing into the directory first before executing the script, and I've tried executing the script as the owner/user of the cpanel account (which is generally how the script is run from the command line). Always the same message. I temporarily tried adding the user to the wheel group (terrible idea long-term I know), but even that didn't work.
I thought it must be some sort of cpanel or server issue, and reached out to the host of the VPS but they didn't think so. The developer of the app is no longer reachable. My guess is it's something he could fix in 5 minutes, I just have no familiarity with this framework.
I've reviewed everything I can online several times and just don't see anything relevant...
Any leads would be greatly appreciated!

Tomcat on Mac OS Yosemite (for iteraplan)

for those who are familiar with the web application iteraplan, I really need help. I've been having trouble getting iteraplan to work on my Mac because some factors or requirements can't be fulfilled.
For this reason I needed to install Tomcat since it's a web application but I'm a newbie to it. Tomcat doesn't work even though I installed it properly, moved it to the right folder and made sure that Eclipse recognizes it as a server. When I'm trying to open anything on Tomcat on my localhost I can't open further pages of Tomcat because I always receive the same error:"The requested resource is not available" When I'm trying to run the web application iteraplan through my terminal, the localhost doesn't open either and I get the same error.
I already changed most of the server file (which seems necessary for getting the web application to work) but that doesn't help either. Is there anything I might gave forgotten? Maybe something I would have to launch or something?
I would be glad for any advice because I desperately need this to work for my thesis.
Thanks in advance.
Yash, have you made sure that your Tomcat installation is working properly? You should be able to access the manager app (usually under localhost:8080/manager/html) and see all running applications, regardless of whether you have iteraplan deployed on the server or not. Also, to run iteraplan, you need a database (details can be found in the iteraplan installation guide: http://www.iteraplan.de/wiki/display/iteraplan34/Installation+Guide). Finally, if you just want to run the application, without modifying the code, it would be simpler to download one of the bundles available in sourceforge (http://sourceforge.net/projects/iteraplan/files/iteraplan Community Edition/). They have a Tomcat server and a database included.

loading tomcat using code

im using tomcat 7 , and im trying to do something nice.
i want to have a little swing program to operate my current project (a site)
i wish to have in that swing application a button to run the server , shut the server and such.
i know there is the option of running it as soon as i start the application but i dont want it. i want to have the option to click a swing button and load it.
for that , i need to run the server by code.
is there a way to load tomcat server via code?
A quick solution for this may be Using RunTime you can do this -
Runtime.getRuntime().exec("startup.bat");
similarly, to stop -
Runtime.getRuntime().exec("shutdown.bat");
Assuming both batch files exist in tomcat bin directory.

Java service wrapper to create service for Java UI application

I have created a Java application which needs to run as a service. For service wrapper I tried using tanuki and other wrapper softwares.
Now, my application does run as a service - however, it runs as a service under SYSTEM and not under currently logged in user.
My application has a UI, which does not show when the application is running as a service. I doubt that this has happened because the service is running under SYSTEM and not under currently logged in user.
When I run the application (without installing it as a service), the UI does show up and I could see the java process running under the current user's id, whereas it runs under SYSTEM when installed as a service.
Now, there is nothing to my application if there is no UI. I need to application to run as a service when the system boots up and the UI needs to show up as well.
Has anyone tried to do what I am doing here and has faced a similar issue. If so, how did you go about resolving it?
Is there a different wrapper service that I could use and not have this issue.
Tanuki's documentation does explain setting a java application as a service, but does not talk about a java applicaiton with a UI and running it under the currently logged in user.
Update
Just so that folks here could get a bit more idea as to what is it that I am trying to accomplish - the behavior that I am trying to have with my app is similar to how Dropbox or Yahoo Messenger or any other software has which starts with Windows boot and continues to run in the background, allowing the users to interact with it using the system tray icon. So basically all of this has been built in Java/Swing. Now when it has come to deployment of the app - I can run it standalone but running the jar file or by creating and running an executable wrapper for it. However, I want the software to start with Windows boot and continue to run as a service in the background, while allowing the user to make changes and interact with it via lets say bringing up the UI from a system tray icon that it sets.
As of now, it does run as a service successfully. It performs all the actions that it ideally should - there just is no system tray icon to bring up the UI and make changes to its configuration.
Update - 2
Ok.. I tried advanced installer and it does wrap up everything for me to generate an exe installer for windows. Now all I need is to auto-start the software. Can anyone help me with this? I don't see an option in Advanced installer to automatically have the program add itself up in the auto-start.
Link to tanuki's doc http://wrapper.tanukisoftware.com/doc/english/faq.html
Rohan,
Please take a look at the following page:
http://wrapper.tanukisoftware.com/doc/english/prop-ntservice-interactive.html
You will need to mark the Service as interactive and then run as the SYSTEM user in order to get your GUI to show up on the first logged in desktop.
The problem is that Microsoft changed what services are allowed to do starting with Windows 2008 and Vista. This means that starting with these versions, the GUI will always show up on a sandboxed desktop which the user will need to switch over to.
If you want to show a GUI on all desktops, in all versions of Windows, you will need to run the JVM within the desktop.
Cheers,
Leif
I wanted to comment on your question, but I don't have enough reputation to do it. So I'm misusing the answer function now.
I have a similar problem. I used the tanuki wrapper for a while now on a Windows XP machine and the Swing GUI was shown to all users who logged in.
Now I migrated to Windows 2008 Server and configured the current version of the tanuki wrapper like this:
wrapper.ntservice.interactive=true
wrapper.ntservice.hide_console=true
(see documentation here and here)
The Windows service runs under the LOCAL SYSTEM account.
But the GUI is still not shown. Did you find any solution to the problem?
Don't think you should have a UI with a service. Put it in the startup group instead ?
What's does the UI and application do?

Prevent a user from terminating a java program?

I want to install a monitoring system on a computer (the program is a jar file) and run it on start up every time any user logs on. However, I don't want the user to be able to terminate it since then it won't be able to be monitored any longer.
We have tried several ways:
Installing it as a service - the problem here is that our program doesn't work any longer; it can't connect to the computer that's monitoring it. We used "Yet Another Java Service Wrapper" for this, and looked into some other wrappers as well that could help us install it as a service.
Running the program on start up (using the folder startup), but not giving the basic user the privileges to edit/delete/mess around with the files. However, this seems to slow the whole computer down? This doesn't happen when we run the bat file executing the jar directly. Another issue with this is that the user can just go to the task manager and kill the java process.
We tried a variation of the previous one to solve the issue of the process being killed, by having another process. One will spawn the other and these 2 processes will keep tabs on each other. If one terminates, the other detects it and runs it to start it up again. Although it can have issues if the user is fast enough in killing both processes before either is respawned again, the bigger issue is that it sometimes has problems with connecting to other computers. We didn't have this problem when it was just 1 jar.
Does anyone have any idea on how these problems can be solved?
The context here is windows, but if you have suggestions for linux and mac that would be nice too!
Way to go is to run the program as a service. You should investigate any trouble between your application and your system's firewall. If you have windows firewall activated, you should add an exception for java.exe or javaw.exe.
In order to give elevated privileges to your program, you can set the service to run as another user. You can do this from the "Log on" tab in the service properties.
You'll want to have the program started under a user with elevated permissions. On WIndows this would the the Administrator, linux would use root. On Windows, its likely that you will need to start it as a service. But I really don't know why that would hinder the network communications.

Categories

Resources