Deploying the Application

Preparing Application for Deployment

In production environment, application and logging configuration will be read from files stored in a dedicated directory on the server, creating a more secure environment. You may also choose to generate application keys directly on the server, thus avoiding transmission of the keys over networks during the upload process. Storing application and logging configuration in a directory separate from the application will also prevent an accidental override of the files during an update.

If you haven't yet written an application, please download a sample web app from LineDrop's repository:

Play/Scala Web Application

Open build.sbt on the root of your application project and update name and version. For example:

On your machine, browse to your home directory and then add a new directory.

Name the new directory deployment. All files to be uploaded to the server will be stored in the deployment directory.

Application Configuration

Copy application.conf from the conf directory of your project and paste it into the deployment directory.

Rename the file to production.conf.

Open production.conf in a text editor and update the following settings:

  • play.http.secret.key
  • version
  • sa block: key, name, and email
  • server block: environment and url
  • any other settings as needed.

Example of an application configuration:

Play/Scala Web Application Configuration

Log Configuration

Copy logback.xml from the conf directory of your project and paste it into the deployment directory.

Open the file in a text editor and change the log file location in the FILE appender section to /var/www/application_log/application.log. Application is the name of your application.

For example, /var/www/code_log/application.log.

Change all logger levels to INFO or above.

Example of a log configuration:

Play/Scala Web Application Log Configuration

Building Application for Production

Open Terminal and browse to the project root. Build a distribution version of your application.

sbt dist

Wait for the process to complete. The final ZIP archive will be placed in the target/universal/ directory of your project. The file will be named application-version.zip, where application is the name of your project and version is the release version number, both defined in build.sbt. For example: code-0.2.zip

Copy the application-version.zip file to the deployment directory.

Server Scripts

Download the collection of application maintenance scripts:

LineDrop Server Scripts

The collection contains several scripts to make application deployment and maintenance a straight-forward process.

  • Setup: creates production directories, unzips and installs the application.
  • Go: starts MongoDB, then starts the application; run this script after server reboot.
  • Start: starts the application.
  • Stop: stops the application.
  • Update: updates the application to a new version. Requires ZIP file of the new version to be in the same directory as the script.

Configuring Scripts

Modify APP_DIR and APP_DIR_CONF variables in each script to reflect the name of your application. The name should be the same as in build.sbt. For example:

Copy the scripts to the deployment directory.

Reviewing Deployment Directory

Please verify that the deployment directory contains all files.

  • application-version.zip
  • go
  • logback.xml
  • production.conf
  • setup
  • start
  • stop
  • update

Uploading Configurations and Scripts to the Server

In Terminal, browse to deployment directory.

cd ~/deployment

Connect to the server with the SFTP connection script.

~/connect_sftp

Upload all deployment files to the server. The files will be saved on the server in the user’s home directory.

put *

Exit SFTP connection.

exit

Starting Up the Application

Connect to the server with the SSH connection script.

~/connect_ssh

Set permissions to read, write, and execute for all scripts.

chmod 700 go setup start stop update

Run the setup script to create production directories and move configuration files.

sudo ./setup

The script executes several tasks:

  • Creates production directories on the server. Application is the name of your application, defined in APP_DIR variable in the script.
    • /var/www/application
    • /var/www/application_conf
    • /var/www/application_logs
  • Moves production.conf and logback.xml to /var/www/application_conf.
  • Unzips the application archive and copies the new directory to /var/www/application.
  • Deletes the original the ZIP file and the staging archive.
  • Starts the application in the background.
  • Removes an empty log directory from your home directory; it is created automatically when the application starts.

Close your SSH session.

exit

By now the application has been deployed and is running on the server. However, it is not yet connected to the reverse proxy server.


Next: Installing SSL Certificate