Skip to content

How to install Jobsworth 5 on Ubuntu 16.10

Lando edited this page May 11, 2017 · 2 revisions

This is a step by step rough guide to install jobsworth from scratch in a clean Ubuntu Server 16.10 computer.

Note that this may not work on previous versions of Ubuntu since the way to create services has changed since version 15.

Note: If you prefer, there's also a script to execute the installation automatically in the jobsworth-installer project. The script basically executes all the steps described below and it also works on some older versions of ubuntu.

0 INSTALLING VIRTUAL MACHINE

These instructions were tested installing jobsworth 5.0 beta 2 on a Ubuntu Server and Desktop 16.10 and virtual machine running in Virtual Box on a Windows Host. If you install Ubuntu Server, it does not have a visual interface (just command line), so you will have to access the website from your host machine.

There is also virtual machine already configured if you don't want to configure it yourself. It can be downloaded from here. Otherwise follow the steps below.

You can do this in several ways, what I did was:

  1. SetUp a new Virtual Machine in Virtual Box with a Bridged Network
  2. Install Ubuntu Server 16.10
  3. Get the IP of the VM using: ifconfig -a
  4. Make sure your VM responds to ping
  5. Install MySql, Tomcat and Then Jobsworth (as described below)
  6. Access Jobsworth from a browser in the host using http://<ip-of-virtual-machine>:8080/

If you are using a VM like in this tutorial, it is recommended that you install OpenSSH in the VM, and putty and WinSCP on the host to access it from the host. To install OpenSSH (if not installed already):

sudo apt-get install openssh-server

1 INSTALL PRE-REQUISITES

1.1 First Install My SQL

In ubuntu type

sudo apt-get update
sudo apt-get install mysql-server
#It will ask you to set the root password, remember it

#Next let's create a new database and a user (in this step it will ask you for the password set before)
mysql -u root -p

Now it will ask for the password you set before.

The you need to create the database that will be used by jobsworth.

Also we will create an user so we do not have to use root from the application. In this script the user will be jw with the password: jobsworth. (if you change this remember it because you will use it later)

CREATE DATABASE jobsworth CHARACTER SET utf8 COLLATE utf8_unicode_ci;
create user jw@localhost identified by 'jobsworth';
grant all privileges on jobsworth.* to jw@localhost with grant option;

1.2 Install TOMCAT

For tomcat we will neee to install the JDK

Java JDK

sudo apt-get install default-jdk

Then we will add a tomcat group and user (we will use this to run it as a service, so it's optional but recommended)

Tomcat User

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Recommended: add your linux user to the group:

sudo usermod -a -G tomcat yourUserName

Download TOMCAT

Now we will download the tomcat compressed file (This version worked for me without problems)

cd /tmp
curl -O http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M19/bin/apache-tomcat-9.0.0.M19.tar.gz

Then extract the file into the tomcat installation directory

sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-9*tar.gz -C /opt/tomcat --strip-components=1

Set tomcat folder permissions

Set the appropriate folder permissions, you could also add permissions for your user if you want

cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/

Tomcat Service

Now we will add the tomcat Service, in this step you will write the tomcat.service file Be sure to change the JAVA_HOME var to the one you installed. If you don't know which one is it Then execute the command sudo update-java-alternatives -l to get it

Lets edit the service file with the following command (you can use your preferred editor if you want instead of nano, as long as you have permissions)

sudo nano /etc/systemd/system/tomcat.service

You will have to add the following text in the file, changing the JAVA_HOME to your own:

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Now We will reload the service daemon so it reads the file, start the service and review the status

sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat

# If everything was ok, you can enable the service so it starts automatically
sudo systemctl enable tomcat

At this point you should be able to access the tomcat start page at http://<ip-of-virtual-machine>:8080/

Let's stop the service to configure the rest without problems.

sudo systemctl stop tomcat

OPTIONAL: Edit the tomcat-users.xml file

Edit the file so you can access the manager tomcat pages

sudo nano /opt/tomcat/conf/tomcat-users.xml

You should add the following lines between the tomcat-user tags:

<tomcat-users . . .>
  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <user username="admin" password="jobsworth" roles="manager-gui,admin-gui"/>
</tomcat-users>

Also, if you are accesing the manager or host-manager apps from outside localhost Then you should edit the following files, editing the regexp of the allowed ips

sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml

My files ended up looking like this:

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
     allow="(127|192)\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>

The original third line was:

     allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

2 INSTALL JOBSWORTH

2.1 EDIT the context.xml file

This is very important, in this step we will configure the database access for the application

sudo nano /opt/tomcat/conf/context.xml

You should paste the following text. It has already configured the MySql Database with the user we set before, if you changed something then update this too. This file has the comments stripped and does not have the email configured. To see the original template file go to: https://github.com/ari/jobsworth/blob/master/config/context.example.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context swallowOutput="true">
  <Resource name="jdbc/jobsworth"
            removeAbandoned="true"
            auth="Container" type="javax.sql.DataSource"
            maxActive="100" maxIdle="30" maxWait="10000"
            username="jw" password="jobsworth"
            driverClassName="com.mysql.jdbc.Driver" batchSize="-1"
            url="jdbc:mysql://localhost:3306/jobsworth?autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull&amp;useUnicode=true&amp;characterEncoding=utf8"
            validationQuery="select 1"/>
  <Parameter name="config.domain" value="acme.com" override="false"/>
  <Parameter name="config.productName" value="jobsworth" override="false"/>
  <Parameter name="config.ssl" value="true" override="false"/>
  <Parameter name="config.storeroot" value="/var/jobsworth/assets" override="false"/>
  <Parameter name="config.email_domain" value="acme.com" override="false"/>
  <Parameter name="config.email_replyto" value="jobsworth" override="false"/>
  <Parameter name="config.email_from" value="jobsworth" override="false"/>
  <Parameter name="config.email_prefix" value="'[jobsworth]'" override="false"/>
  <Parameter name="config.smtp_host" value="mail.acme.com" override="false"/>
  <Parameter name="config.smtp_port" value="25" override="false"/>
  <Parameter name="config.smtp_domain" value="acme.com" override="false"/>
  <Parameter name="config.secret" value="changeThisValueToSomethingRandom" override="false"/>
  <Parameter name="config.secret_key" value="f8892f2aebc7b250a31b9678eee0c3a784bbb9f5d5384884d0d2204dde2d446823e15fcbeeb3ce526a407956ca8ff6543367e67386b075571a7277f54a73a5f9" override="false"/>
  <Parameter name="config.error_email_prefix" value="'[jobsworth error]'" override="false"/>
  <Parameter name="config.error_sender_address" value="jobsworth@acme.com" override="false"/>
  <Parameter name="config.error_exception_recipients" value="['support@example.com','sysadmin@example.com']" override="false"/>
  <Parameter name="config.cache_path" value="/var/jobsworth/cache" override="false"/>
</Context>

2.2 Create aplication folders

Now lets create the special folders used by the app and give the necessary permissions:

cd /var
sudo mkdir jobsworth
sudo chown tomcat jobsworth
sudo chgrp tomcat jobsworth
sudo chmod 774 jobsworth

sudo mkdir jobsworth/assets
sudo chown tomcat jobsworth/assets
sudo chgrp tomcat jobsworth/assets
sudo chmod 774 jobsworth/assets

If you don't do this, you might get errors when logging in.

2.3 Copy WAR file

Let's go to the tomcat installation folder and remove the original ROOT folder

cd /opt/tomcat

# CAREFUL!: remove or move to other folder the original ROOT folder inside webapps
rm -rf webapps/ROOT

Now copy the ROOT.war file from the latest github release, you can download it from here: https://github.com/ari/jobsworth/releases, and save it inside the /opt/tomcat/webapps folder, or you can try this to download it directly (untested!!):

cd /opt/tomcat/webapps
curl -O https://github.com/ari/jobsworth/releases/download/5.0b2/ROOT.war
cd ..

AFTER downloading the file, set the permissions to the tomcat user

sudo chown tomcat webapps/ROOT.war
sudo chgrp tomcat webapps/ROOT.war

2.4 Now lets start tomcat again

sudo systemctl start tomcat

# OPTIONAL: give permissions so everyone can read the logs
sudo chmod 664 logs/*

Wait a little and try to access jobsworth from a webbrowser using: http://<ip-of-virtual-machine>:8080/ (remember to put your corresponding ip address)

You should see the login page (it might take a while the first time) Now you can login with the default admin user and password as password.

If you see any errors look at the files in the /opt/tomcat/logs directory.

Most of these steps were taken from these sites:

MySql installation: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04 without the secure installation

Tomcat installation: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 without the firewall config

MySql And Jobsworth Configuration: http://leonardobrasileiro.blogspot.cl/2013/10/configurando-o-jobsworth-clockingit.html to create the db and the db user

Various https://github.com/ari/jobsworth/wiki

Original article can be found here