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

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.

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

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

Nginx + PHP5-FPM break some web app which works on Apache + PHP5

I have a vps with Debian 6.0.5, installed with Nginx + PHP5-FPM using package from dotdeb using a setup script introduced by a blog. Everything works like charm for my wordpress and phpmyadmin.
Now, I wanted to install beanstalkd into the vps, and decided to use some PHP web app to manage beanstalkd. I've installed phpBeanstalkdAdmin and Beanstalkd console. Both failed to run properly.
phpBeanstalkdAdmin returns a page like
phpBeanstalkdAdmin
Home
About
layout()->content?>
Beanstalkd console displayed an empty tube once server is configured. Before that, the error message is also missing.
When I install both in my local machine running XAMPP, which is Apache + PHP5, and point the configuration to my vps' beanstalkd, it works. Further more, before configuration Beanstalkd console would display proper error message unlike when running on Nginx + PHP5-FPM.
I've tried to use XDebug and didn't find any error or anything wrong when stepping through both web app. Both web app utilizing Zend Framework. I didn't find any specific setup which is required to run Zend Framework on Nginx + PHP5-FPM, and have tried various addition of the basic configuration such as fixing Path_Info & PHP_SELF
I would really love to use Nginx instead of Apache for my vps as I have a small box.
Any insight or guide on this issue is much appreciated.
Check the value of PHP's short_open_tag on both (should be listed in phpinfo). My guess is you need to turn it on for your VPS.

Best approach to integrate netty with openshift

In fact, I'm trying to see which would be the best approach to achieve play framework native support on openshift.
Play has it's own http server developed with netty. Right now you can deploy a play application to openshift, but you have to deploy it as a war, in which case play uses Servlet Container wrapper.
Being able to deploy it as a netty application would allow us to use some advanced features, like asynchronuos request.
Openshift uses jboss, so this question would also involve which would be the recommended approach to deploy a netty application on a jboss server, using netty instead of the servlet container provided by jboss.
Here is request for providing play framework native support on openshift There's more info there, and if you like it you can also add your vote ;-)
Start with creating 'raw-0.1' application.
SSH into the server and
cd $OPENSHIFT_DATA_DIR
download and install play into a directory here. $OPENSHIFT_DATA_DIR is supposed to survive redeploys of your application.
Now you can disconnect from SSH.
Clone the application repository. In the repository, there is a file .openshift/actions_hooks/start. It's task is to start the application using a framework of your choice. The file will need to contain at least (from what I know about Play)
cd $OPENSHIFT_REPO_DIR
$OPENSHIFT_DATA_DIR/play-directroy/play run --http.port=$OPENSHIFT_INTERNAL_PORT --some-other-parameters
Important
You have to bind to $OPENSHIFT_INTERNAL_IP:$OPENSHIFT_INTERNAL_PORT. Trying to bind to different interface is not allowed, also most of the ports are blocked.
To create some sort of template, save the installation steps into .openshift/action_hooks/build file. Check if play is installed, if it is do nothing, if it's not, execute the installation process.

Deploying my first play app, i'm so lost

I've decided to go with Apache as the http server in front of my play app. The server team at my company says they installed Apache and Python and play on the target server. I'm code complete, so here's where I don't know what to do next.
How do i "compile" my play java app?
What folders do I deploy, which ones do I not deploy?
Where on the target server hard drive do I place the webapp I'm deploying?
How do i tell apache where I deployed the play webapp to on the disk?
How do I make it so that apache and play are now always running and don't require I be logged in on the target server?
Yeah I'm new to linux
Please help I'm lost.
Thanks in advance
Josh
Read the Preparing for production section before anything else.
How do i "compile" my play java app?
Play does that for you when you laucnh play start. However you can use the play precompile command before starting the app.
What folders do I deploy, which ones do I not deploy?
app, conf and public. You might have some 3rd party lib dir too.
Where on the target server hard drive do I place the webapp I'm deploying?
I don't think it really matters.
How do i tell apache where I deployed the play webapp to on the disk?
Apache act as a reverse proxy (forwards every requests to your app and serves the reponses back to client). For this you need to edit the apache's httpd.conf
How do I make it so that apache and play are now always running and don't require I be logged in on the target server?
You need to start the apps as daemon threads which I think apache does by default. the command play start should run play in the background.