Deployment - yajatyadav/intellijs GitHub Wiki

Deployment Guide

We will use AWS to deploy.

To Update Deployed Website With Newly Pushed Changes:

Stop service file: sudo systemctl stop intellijs
Stop main project: sudo stop /home/ubuntu/intellijs/target/serving-web-content-0.0.1-SNAPSHOT.jar
Pull changes: sudo git pull
Start project again: sudo mvn package
Start project: sudo java -jar /home/ubuntu/intellijs/target/serving-web-content-0.0.1-SNAPSHOT.jar
Restart service file: sudo systemctl start intellijs

AWS Setup

AWS Setup

Make an AWS Account

  • Choose an Amazon Machine Image (AMI)Cancel and Exit
  • Choose an Instance Type
  • Configure Instance Details Stick with default. Your will launch a single instance of the AMI by using defaults
  • Add Storage Stick with default. Your instance will be launched with 8gb of storage.
  • Add Tags, Tag your Amazon EC2 resources. This is not required but you could name your volume for future identification.
  • Configure Security Group. A security group is a set of firewall rules that control the traffic for your instance. On this page, you can add rules to allow specific traffic to reach your instance. In this example, a web server is setup to allow Internet traffic to reach EC2 instance, this allows unrestricted access to the HTTP and HTTPS ports. Also, this example restricts SSH from my IP.
  • Before you leave your ADMIN session on AWS go to EC2 running instances and find your IPV4 address.
  • Start a terminal session on you localhost.
  • Java Web Application Setup

    Java setup, Maven build and Runtime Test

    Java is two pieces (JDK and JRE), both parts are needed in order to run and build

    $ sudo apt update
    $ sudo apt upgrade
    

    Install Java Runtime Environment

    $ sudo apt install default-jre
    $ java -version
    

    Install Java Development Kit

    $ sudo apt install default-jdk
    $ javac -version
    

    Maven is required to build project

    $ sudo apt update
    $ sudo apt upgrade
    $ sudo apt install maven
    $ mvn -version
    
    Clone, build and test Web Application

    Clone and build repository

    $ cd
    $ git clone https://github.com/nighthawkcoders/nighthawk_csa.git
    $ cd nighthawk_csa
    $ ./mvnw package
    

    Run your java project, after test ctl-C to stop service

    $ cd
    $ java -jar nighthawk_csa/target/csa-0.0.1-SNAPSHOT.jar
    

    Test on localhost browser

    localhost:8080
    

    Website Deployment Preparation

    Establish a service to enable Java Web Application to always run on Server To run and start application automatically it will require a the JAR file from previous step to run from a .service file. In this service file we are providing details of the java runtime service: * start after “network.target” has been started * the ExecStart is the same as command you validated to executes JAR

    Create a 'service' file as administratr:

    • sudo nano
    • change nighthawk_csa reference or jar file name as applicable to your project
    • replace User=pi with User=ubuntu if applicable

    File is located at /etc/systemd/system/nighthawk_csa.service.

    [Unit]
    Description=Java
    After=network.target
    
    [Service]
    User=ubuntu
    Restart=always
    ExecStart=java -jar /home/ubuntu/nighthawk_csa/target/csa-0.0.1-SNAPSHOT.jar
    
    [Install]
    WantedBy=multi-user.target 
    

    Run and enable your service file

    $ sudo systemctl start nighthawk_csa
    $ systemctl status nightawk_csa
    

    If succesfull, enable your service file to be persistant on machine

    $ sudo systemctl enable nighthawk_csa
    
    sudo apt-get update
    
    sudo apt-get install apache2 php5 libapache2-mod-php5
    
    now you should allow overrides by editing the 000-default file, you can do that using the following comands..
    
    sudo nano /etc/apache2/sites-enabled/000-default
    
    now edit the following lines
    
    change "AllowOverride None" -to "AllowOverride ALL".
    
    now execute 
    
    sudo service apache2 restart
    
    to restart apache witht your new settings
    
    now your site should be up and running u can go to /var/ and change the permissions on www, making it writable.
    
    cd /var/
    sudo chmod 777 /www
    
    This will enable you to login using WINSCP and upload HTML pages to your new site. open the browser on your PC and point to 192.168.xx.xx (ip address of you raspberry pi) to view the default page.
    
    You can also install and SQL server using the following comands, with a PHP and SQL running on your server u can have a CMs like Drupal running on it.
    
    sudo apt-get install mysql-server mysql-client php5-mysql
    
    
    Enable Nginx to retrieve Java Web Application on external request (Reverse Proxy)

    File is located at /etc/nginx/sites-available/nighthawk_csa

    server {
        listen 80;
        server_name csa.nighthawkcoders.cf;
    
        location / {
            proxy_pass http://localhost:8080;
        }
    }
    

    Test the configuration to make sure there are no errors:

    $ sudo ln -s /etc/nginx/sites-available/nighthawk_csa /etc/nginx/sites-enabled
    $ sudo nginx -t
    

    If there are no errors, restart NGINX so the changes take effect:

    $ sudo systemctl restart nginx
    

    Register IP address to a Domain + Route to Nginx server

    Goto freenom.com and register your public IP Address to a Domain
    - Domain and Public IP Address match your nginx configuration files 
    + REPLACE freenom config with your-domain and your-public-ip, make one or more a records for each project

    This illustration shows configuration of A records within the domain

    Port forward your public IP address access to your Nginx/RPi server
    - Your Public IP Address needs to connect to your host on Private IP network through Port Forwarding 
    + PROCESS will vary on every home network, but basic premis is to Port forward external port 80 to your Private Host (aka RPi) on internal port 80

    This illustration shows configuration of HTTP, as well as some other common service to access a Private IP host computer through port forwarding. It is always recommended to minimize access points from internet to your home network.

    ⚠️ **GitHub.com Fallback** ⚠️