Newb - run jar in background

How to run the jar and then close the terminal, since I’m accessing the server with ssh session. I would like to still be able to look at MB output…

Are you running the jar on your own server?

Yes, ubuntu.

Strugling with starting with logging, and on boot…

So far I have:

java -jar metabase.jar |multilog t s10000000 n3 '!tai64nlocal' /opt/metabase/log 2>&1 &

But this still shuts down when closing terminal. And does not start on boot obviously…

Hi,

I am usuing ubuntu server, i made an script with the enviromental variables and the java command.

I mean, I made mb-start.sh with this:

#!/bin/sh
export MB_DB_TYPE=mysql
export MB_DB_DBNAME=metabase
export MB_DB_PORT=3306
export MB_DB_USER=xxx
export MB_DB_PASS=xxx
export MB_DB_HOST=xxx

java -jar /home/pytserver/Metabase/metabase.jar

And configure that script to run at startup

I recommend you to set a different db other than the default H2. I was using that and from one day to the other i lost all the info i had (users, questions, dashboards, etc). Then i read that H2 is only for testing and in production you should use another.

Hope that helps you

@cagiraudo Thanks for your help.

I’m trying to keep MB’s log.Because it is so verbose I need the log file to be “managed”.
Also, how do you configure your script to run at startup? It seems to me your java -jar command is not deamonized… and will run in the foreground?

So, this is just my solution. Not sure is the most appropriate... please let me know if you see/have corrections/suggestions.

Installed in /opt/metabase. Created new directory for logs in /opt/metabase/log.

Created /etc/init.d/metabase script. Contents below.

Added service to start at boot:

sudo update-rc.d "metabase" defaults

I can now start the script, stop, see status with:

sudo systemctl start/stop/status metabase

To see the last entries in the log, do:

tail /opt/metabase/log/current

The log is managed by multilog. The script creates 3 log files of 10MB, which rotate.

The key command to run metabase is this:

nohup $JAVAPATH -jar $PATH_TO_JAR |multilog t s10000000 n3 '!tai64nlocal' /opt/metabase/log 2>&1

I have still to reboot the server, so the boot part is pending validation.

script /etc/init.d/metabase (I think USER is not needed anymore, just replace with your user):

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          metabase
# Required-Start:    $remote_fs $syslog $time $network
# Required-Stop:     $remote_fs $syslog $time $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Metabase, agile analytics.
# Description:       Metabase is the easy, open source way for everyone 
#                    in your company to ask questions and learn from data.
### END INIT INFO
#
SERVICE_NAME=metabase
PATH_TO_JAR=/opt/metabase/metabase.jar
PID_PATH_NAME=/opt/metabase/metabase-pid
JAVAPATH=/usr/bin/java
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
USER=arcims
cd /opt/metabase
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup $JAVAPATH -jar $PATH_TO_JAR |multilog t s10000000 n3 '!tai64nlocal' /opt/metabase/log 2>&1 &
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
#            kill $PID;
            pkill -f "java -jar $PATH_TO_JAR"
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
#            kill $PID;
            pkill -f "java -jar $PATH_TO_JAR"
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup $JAVAPATH -jar $PATH_TO_JAR |multilog t s10000000 n3 '!tai64nlocal' /opt/metabase/log 2>&1 &
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac

hi all, so i’m going to test this and replay back shortly.
anyway i think that the creators need to take a look at this.

managing a jar file that go’s offline hear and there is quit hard. i do understand the state of the project. but it would be grate if we had an official release with tools such as in this thread to run the app as a service and start getting creative with it. stability and ability to manage the service correctly is critical to the success of this project.

My script is working but doesn’t start at boot, and I don’t know why. There’s another script by another user here: https://github.com/metabase/metabase/issues/2090 (just scroll down until you find it)

Haven’t tried it though.

Hi there, I’m curious if anyone made any progress here? I did get almost the exact same script to work and Metabase launches automatically at start up or reboot of the server, however when it does so it skips the environment variables that set the application database to MySql, as well as the encryption, password strength and port that I want to use.

When I start the Jar file manually however it does login to MySql just fine, and uses the port I want and encryption.

So now I have a situation where the Jar either starts automatically but goes to H2 on its default port 3000 without encrytpion - or will run to the MySql server on the port I want with encryption, but only if I leave an SSH session open in the background.

Frustrating, and I’m sure it is because of something simple, but I’m new at this too.

Thanks.

Nevermind, figured it out. I had the export variables in the wrong place.