Reducing downtime to zero on jetty server with Chef - java

So as I started deploying my web app with jetty server, I noticed there is about a 10 second downtime whenever I redeploy the web app after making some changes. I know there is a solution out there, I have found some good leads such as this one. However since i am using chef i am not sure how to implement this.

The link you have provided is a bash script. Check out chef's own bash resource.
Using bash resource, you can a run a shell script via chef.
This is handy as you already have a script to do what you want to do. So run that script via chef. Of course, there might be a chef specific cookbook/recipe/attribute lying somewhere written. But bash resource is the quickest possible way in this regard to do what you want to do (presuming the bash script you referred is all you need to get the job done).
UPDATE:
Check out my answer where I got something done for which a chef resource does not exists

Related

How do i get the working directory of a windows process in java?

I would like to get the path to the working directory of a specific process (for example for the PID of the process). I am Not Talking about the working or current Directory of the process where my Java Code is running. Its a simple task with Linux, but for Windows i cant find a proper solution. Furthermore, it would be nice, if its a Command or a Framework for Java, because i will need the path in my Code. I am not looking for the path to the executable, also Not for a solution with wmic or process explorer.
Already thanks for the help.
I already tried commands like tlist and wmic, but those solutions cant be utilize in my code. I am looking for a solution that i can use without special installations on Windows.
JNI and JNA provide means to call directly into native libraries from Java code, and it is feasible to use these to call out to Windows libraries.
There is a github project that appears to be close to the need: https://github.com/kohsuke/winp. Perhaps you can add the needed code and send up a pull request, or fork the project.
Note that any solution here is going to be windows-specific, meaning the application using it will not run on another platform. Given the nature of the question, that doesn't sound like it would ever be a concern.

Call Unix Shell commands from Servlet/JSP

I need to call some Unix commands from my Servlet.
I have some Perl script, but I want to "translate" them into Java.
Here is something that I want to do on Java, but that I've made in Perl:
system("myfolder/myscript.sh > /myfolder/logs/myscript.log");
Is it possible to do this on a Servlet?
Yes, but note that redirect is part of the shell you will want:
ProcessBuilder pb =
new ProcessBuilder("/bin/sh", "-c", "myfolder/myscript.sh > /myfolder/logs/myscript.log");
pb.start();
Short answer:
it's possible but it's bad design, and can pose a security risk.
better to flag somehow that the script needs to run and check the flag via script
Long answer (following the commments):
Servlets are usually used to provide a user interface (or api) to something, for example accessing data or in your case triggering an action. As such, they imply the possibility of access from a remote resource such as a remote computer. In some (actually most) cases, that remote computer may even be out of the network, for example somebody's home.
Every server which is exposed to the outside world has the potential of being hacked or attacked in some way, with the risk being directly related to the level of interest this resource poses.
For example, if you work for a big company (which is then noticeable by hackers), and this servlet is used to trigger a build in your local repository, and you decide that developers will be able to work from home and need to login in order to trigger a build or check their build status, it means that anyone with the right credentials can potentially access the servlet, from anywhere in the world. Now lets assume that your perl script needs to access your CI server for some data, and your source repository for another data (maybe it even copies the sources instead of letting the CI server do it). In this case, you just created a direct link between someone sitting somewhere in the world, to the company's source code. It also means that even if it's too hard to penetrate your incredibly secure service because you spent a vast amount of time closing all potential gaps, they may still be able to trigger many unnecessary builds, and if you work in Continuous Deployment even make those builds go to production (maybe causing a DOS attack or service disruption). If at some point someone decides that the script also needs to get a parameter from the servlet, you've even made the hacker's life easier and could eventually give him access to your system.
All I described in the previous paragraph may be completely irrelevant to your case, you might be developing a service which will run on your home computer and won't interest anyone but yourself, but this does not change the fact that this is bad design (which might be ok for home use by the way).
What I said in the short answer is that it's better to have servlets flag the system that an action is needed, for example set a flag in DB or even in a file, in this case a hacker's life would be much more difficult, as there's no direct link. This also makes the servlet respond immediately, possibly automatically updating on status, instead of waiting for the perl script to finish running.
Did u try Jsch.It can do ssh and execute shell commands.

Moving files from Tomcat Linux to another Linux Server

I've taken a job where years ago their webmaster setup an intranet using Tomcat on a linux server. The users can create something in the test environment and then click "make live" and the Linux/Tomcat moves the file to a Linux/live PHP web setup.
I'm clueless how they're moving the files. What would be a common tool to do this in Tomcat and Java?
I realize this is vague, but any help would be appreciated. Let me know what other info would be needed.
Also there is a duplicate MySQL database in both servers. I'm guessing the Tomcat setup is writing duplicate info to both databases, but I don't see how the files are getting moved.
This sounds like the website content is completely stored in the database and written over to the other server.
Theoretically you could also have a rsync shell script and call that from php to actually synchronize files over to the other server.
If the "Make Live" is on click and happens immediately its either a direct db access or some script based synchronization.
If it takes a while it could be a cron-job. Maybe you should just check this anway crontab -l will work.
There are several options, you actually open the *.php which the user can edit the content and see where the make live button brings you e.g. "Post Form to *.php" and than you check what that script is doing or you show us the package (what i would like to see but not suggest if you are working on a companies site).
Get back here with some more information, so i can expand the answer for you. Maybe you should also clarify why you are clueless, state what you have checked already, the info i would require is the actual site which has the make live button on it, it will lead to the next site or a script which will probably show what the site is doing.

Run Java programs from PHP in a sandbox

I have a little question: we have to run Java programs and parts of the code will be uploaded by the users.
So I want to know what's the best way to run them? I know 2 possible ways,
exec("javac Usercode.class") and then run the whole thing with exec("java Main"), but I tried it with exec() and it don't work. maybe because the http is not root? But I don't know exactly why.
http://php-java-bridge.sourceforge.net/pjb/ ?
Any suggestions?
And another question is, how can I run these programs in a sandbox. we have a Debian server and so it's no problem to execute the command with a limited time, but is there a possible way to run the whole code in a sandbox?
Ideas for sandboxing:
Run in a chroot using e.g. Debian's schroot command. Protects against them accessing files outside of the chroot but not against them doing things like opening sockets etc.
Each user has their own Linux username against which they validate. Commands will then be run under the appropriate username (e.g. by using sudo or a set-uid executable).
Maintain a pool of virtual servers - expensive and complicated but gives best isolation.

How to get jnlp href attribute at run time in Java web Start app (similar to BasicService.getCodeBase())?

I have a single application that I am deploying via Java web Start. I have several different jnlp files for different launch scenarios. I am using DownloadService2 to check for updates periodically. When an update is available, I prompt the user. If they elect to update, I launch a new instance of javaws using Runtime.getRuntime().exec(), passing in the full jnlp url, then I System.exit(0). Effectively, this kicks off an update/restart cycle.
The problem is, since I could have started from one of several jnlp files, I can't simply hardcode the url. I know that I can get the host:port portion of the url from BasicService.getCodeBase(), but is there a way to get the file portion of the url? Currently I am adding a "jnlp" argument to the application-desc similar to the following so that I can retrieve it from args:
<application-desc main-class="my.main.class">
<argument>jnlp=myjnlp.jnlp</argument>
<application-desc/>
I think this will work, but I'm wondering if I am making it harder than it needs to be. Thanks.
Perhaps it would be best to provide this functionality using the DownloadService.
I worked around this issue using the approach described in my question. There doesn't seem to be a better way.

Categories