Running Metabase jar file as a systems service on Ubuntu Server

Hi, I am trying to get the Metabase (v0.24.2) jar file running as a systemd service on Ubuntu Server 16.04.

I have OpenJDK 1.8.0_131 installed

Running java -jar metabase.jar works perfectly, but I cant seem to get it going as a systemd service.

This is the metabase.service file I have:

[Unit]
Description=Metabase server
After=syslog.target
After=network.target

[Service]
ExecStart=/usr/bin/java -jar /var/metabase.jar
User=administrator
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=metabase
Restart=always

[Install]
WantedBy=multi-user.target

When I start the service, I get:

Metabase Initialization FAILED:  Assert failed: Unable to connect to Metabase h2 DB

I assume the issue is something incorrectly configured in the service file… Any ideas?

Thanks!

I’m not very familiar with systemd service files, but this reference https://www.freedesktop.org/software/systemd/man/systemd.service.html has a section called “Command Lines” where it shows using Environment=.

Thoughts:

  • What is the working directory when this service is being started?
  • Does the running user have access to create a database file (if that’s the default behavior)?
  • Maybe specifying MD_DB_FILE with the Environment= directive can help?

This sounds like you’re using the default h2 database (for production, a dedicated database like postgresql is recommended). This means that the user running Metabase needs to have filesystem access for storing database files. Set WorkingDirectory to a path where the user (you configured it as administrator) has write access.

1 Like

This is my exact service file:

[Unit]
Description=Metabase

[Service]
Environment=MB_DB_TYPE=h2
Environment=MB_DB_FILE=/home/william/metabase/metabase.db
Environment=MB_EMOJI_IN_LOGS=false
ExecStart=/usr/bin/java -jar /home/william/metabase/metabase.jar

[Install]
WantedBy=multi-user.target

I’d probably lean toward the WorkingDirectory= directive mentioned by @wvengen, but based on the file you posted, the problem might be multiple Environment= directives – I think you’re supposed to define multiple variables on a single line.

Something like:

Environment="MB_DB_TYPE=h2" "MB_DB_FILE=/home/william/metabase/metabase.db" "MB_EMOJI_IN_LOGS=false"

Also, it seems like you can use EnvironmentFile={path} to make things a little cleaner in the service file.

I should have elaborated. I am not having any problems, and just offered my working service file as an example of how to make one.

I run mine as a system service, so it runs as root and doesn’t have any problem accessing any necessary files.

@william Oops, I should’ve looked at the name :slight_smile: good to know multiple entries work for the environment!