Run Play application dist in production as daemon [duplicate] - daemon

This question already has answers here:
Scala start Play server in production
(4 answers)
Closed 7 years ago.
With my Play application built with command activator stage, I want to deploy it to production server. However, when I use the start script to start the app, it seems the app is not forked into a separated JVM. Thus if I try Ctrl+C, it will kill the app. Ctrl+D does not do anything, unlike when I use the command activator start, where Ctrl+D is used to detach from the log.
Is there anyway to run the Play app as daemon in production (with no SBT, Activator installed)?

Depending on your system, install it as a service ( in /etc/init.d for example), use a tool like supervisord or daemontools. There are plenty of other options as well

Related

How to deploy angular2 on tomcat?

First I'd like to describe my set up:
I have a web service, let's call it "Cars", written in Java, that I've tested in eclipse with tomcat v6, working local (it was a requirement, so that once it works locally I can switch to do it with a "real" tomcat server so others can access). It works, it access the database, it offers an answer for certain URIs and so on.
I have coded in Plunker an angular 2 application, "WebCar", and I now want to run that on my computer, with a Tomcat server (unless there is a better way of doing it, I've been told to do it with Tomcat. Since I do not know any better option, that's why I talk about tomcat all of the time). With eclipse, I have already managed to get the app running, using palantir plugin for typescript https://marketplace.eclipse.org/content/typescript , and then running the project with a server-launch.js which contains require('lite-server'); , this allows me to see the same I saw on plunker, so, it works, but before I upload anything to the business servers I wanted to check everything works (hence the set up, which may not be necessary but it's what I come up with).
I now want to go one step further and use, if possible, tomcat v6 to run my angular 2 app, instead of simply using that lite server, so that I can test that it works, and then uploading it to a "real", remote server.
I would like to know what options are there, what would be a better option, and anything that is required to make an angular 2 deployment properly. So far I've found this
https://stackoverflow.com/a/34408495/6028947 " You only have to deploy
.js files, since anyway browser won;t" which I don't fully get,
http://jspm.io/ which is for SystemJS (I have an older version of
Angular 2 and use config.js)
https://stackoverflow.com/a/37568235/6028947 which talks about
angular-cli or webpack, which makes a bundle but if I got that
running, I still don't know what to do with it to upload to Tomcat
and then connect it to my web service.
So maybe the question should be (I don't know for sure): Once you get your angular 2 code bundled, what's next?
Btw there are a few other questions on stackOverflow, similar to this, but as far as I've seen, without any answer at all or with answers only obliquely related to this (and of course, nothing resembling a guide or step by step required)
Thanks to #nuzz for this ..
I'm running a little script to build the project and then copy it to tomcat. I'm telling angular what the base directory is that it will run under in tomcat.
#!/bin/sh
ng build --base-href /angular/ --prod
mkdir -p /home/xxx/apache-tomcat-8.0.37/webapps/angular
cp -R /home/xxx/angular-clitest/dist/* /home/xxx/apache-tomcat-8.0.37/webapps/angular/
Once thats run, start tomcat and you can access it at: http://localhost:8080/angular

Eclipse IDE remote rebug and remote edit a legacy webapp

I am in a bind here, what's happening is I have a legacy webapp which uses an in-memory database. The app requires 64GB of RAM just to launch and it takes at least 30 minutes to start.
I have to make updates/fixes to this application. Obviously it is impossible to launch it on my PC so everything has to be done on the server. I have considered setting up an Eclipse IDE on the Linux server where this app runs, but that introduces a set of new issues. I really would like to continue using my PC's Eclipse IDE and make edits to the app.
I am able to use the remote debugging capabilities of Eclipse IDE and launch this app from the linux server no problem. However this is not enough. After I make an edit, I need to be able to save/compile the file, and load this change into the server relatively quickly. I can't wait 30 minutes every time I make some updates to the app.
Can anyone recommend ideas on what to do in this scenario? Ideally I would love to be able to launch the app in DEBUG mode inside the Linux Eclipse IDE on the server and connect to this instance using remote debugging from my local/Windows IDE. I would like to make changes in my Windows Eclipse IDE and then quickly copy the files over to the linux server, pick them up in the Linux Eclipse IDE, compile them in the Eclipse IDE instance running in debug mode, and effectively "hot swapping" the changes, thereby avoiding the need to wait 30 minutes for the app to start back up... However when I try to do this, there is a caveat... I can't seem to be able to launch the webapp in Linux Eclipse IDE in both DEBUG mode and also remote-debug-connect to it, the error I am getting in Eclipse is:
"Cannot load this JVM TI agent twice"
I get what is going on: the local debugger is launching tomcat with the -agentlib:jdwp parameter and on top of it, I am trying to force it to also start up with the same arguments and so it complains, but is there some way to trick it into allowing me to remote connect into this debug session from my Windows server?
I managed to solve this issue by updating Tomcat's context.xml to support reloadable mode:
<Context reloadable="true">
And in the app to set it to reloadable in WEB-INF/web.xml:
<web-app reloadable="true">
Now I am able to make edits in my local windows Eclipse IDE, Save them, and they automatically get updated on the server side.

Deploying Play 2.3 on production

I have developed a Scala/Play webapp and now I am trying to deploy it on production.
What is the recommended "best way" of doing that?
The documentation mentions only runnig it from play console, which does not seem very robust (in case of machine restarts etc).
There are apporaches to wrap the app into a war file and deploy on Tomcat7 (e.g. play2war), but they do not seem to be actively developed (e.g. there is only beta support for 2.3, the plugin is not available from maven repo etc).
What is the right way of doing this?
If you host the application on Windows then take a look at Yet Another Java Service Wrapper which wraps the application in a Windows service that will keep it running, even after restarts.
If you run it on Linux then take a look at Supervisord and Monit, which monitors the application and starts, restarts and stops it when needed.
See the following links for tutorials:
How do I run a Play Framework 2.0 application as a Windows service?
http://marcovanduijn.blogspot.nl/2011/08/run-play-framework-application-as.html
http://blog.fgribreau.com/2013/09/how-to-make-play-framework-2-work-with.html

How do I make the web server run "constantly"?

I have a Play application at ec2 which I just have deployed. Everything seems fine, it's visible in the Internet. However, it seems fine only as the server is working. What I mean is that when I connect to ec2 via ssh and then launch the server by play run, only since then it's visible in the Internet and works fine. I know it's obvious. But I tried to run it in background by play run& and it never worked:
$ play run &
[1] 2470
$ jobs
[1]+ Stopped play run
$ play run&
[2] 2494
$ jobs
[1]- Stopped play run
[2]+ Stopped play run
Have I been doing something wrong? But what and what should I do?
You should prepare your application for production as discussed in the docs. You might also consider running it behind Nginx or Apache or another web server.
Besides also recommending running production using a reverse proxy with Apache or Nginx. (Pretty much the de facto standard these days on Linux), you can also deploy it using the play dist command. Basically, it will compile your code into a package and put it into a zip file.
You can unzip your zip file wherever you want to run your application then you can just run it with:
$ ./<yourapplication>/bin/<yourapplication> -Dhttp.port=<whichever port you want to run it at> &
Make sure you have the java executable in your PATH and this method will avoid having any dependency with the Play application itself. Eventually, you'll probably want to create a Linux init script if you need to deploy your app into multiple servers say behind a load balancer -- So you can your just run service <your-app> start or service <your-app> stop
More info here: http://www.playframework.com/documentation/2.2.x/ProductionDist.
Also, make sure you look at the latest play documentation as it gets updated pretty often.

In GAE how do you *stop* running your app?

I'm on Eclipse (Helios) using GAE SDK 1.5.2, etc. (Just updated everything, today.)
"In the old days..." (earlier SDKs), when I ran/debug my app locally, it would create an app on my machine (Mac, OS-X 10.6.latest) and, when I wanted to quit it, I would just CMD-Q that app.
Now, when I launch the app, it appears to run as a sub-process of Eclipse (assumption on my part -- I can't find any separate app that's running), and I can't seem to figure out how to quit the app.
The specific problem I'm having is, after I change something and select Run -> Debug as... -> Web Application the 2nd time, I get "address in use" socket-binding error.
[ERROR] Unable to bind socket on port 9997 -- is another session active?
java.net.BindException: Address already in use
I suspect that, yes, another session IS active (the one I started just 2 minutes ago!), and my question is: how do I stop that session?
Thanks!
If you look in the debug window you'll see your running processes. Just select one, right click and 'Terminate':