Metabase as a service for Ubuntu

This is how I installed Metabase in Ubuntu using systemd and services: I am using MySQL and configured the service to get started at system boot time and have the possibility to stop it when I want..

Install Metabase

Downloaded the jar file from metabase.com and put it inside /var/www/metabase

wget http://downloads.metabase.com/v0.229.0/metabase.jar -P /var/www/metabase

 

Create the service

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

 

Paste the following inside this file:

[Unit]
Description=Metabase service
[Service]
User=root
# The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/var/www/metabase
#path to executable: executable is a bash script which calls jar file
ExecStart=/var/www/metabase/metabase
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

 

Create a Bash Script to call the service

I created the bash file inside my metabase folder:

sudo nano /var/www/metabase/metabase

 

I prefer to use MySQL instead of H2 default database so: I added the necessary environment variables for that in my script.

#!/bin/sh
sudo /usr/bin/java -DMB_DB_TYPE=mysql -DMB_DB_DBNAME=metabase -DMB_DB_PORT=3306 -DMB_DB_USER=<username> -DMB_DB_PASS="<password>" -DMB_DB_HOST=localhost -jar metabase.jar

 

Give it execute permission:

sudo chmod u+x /var/www/metabase/metabase

 

Start the Metabase service

sudo systemctl daemon-reload
sudo systemctl enable metabase.service
sudo systemctl start metabase
sudo systemctl status metabase

Upgrading Metabase

Suppose I want to upgrade to version 0.29.0 then I do the following:

sudo wget http://downloads.metabase.com/v0.29.0/metabase.jar -P /var/www/metabase -O/var/www/metabase/metabase-new.jar && sudo service metabase stop && sudo mv metabase.jar metabase-old.jar && sudo mv metabase-new.jar metabase.jar && sudo service metabase start