dolthub / doltlab-issues

Issue tracking for DoltLab
MIT License
5 stars 2 forks source link

Doltab needs a systemd file #56

Open bitfactory-sem-denbroeder opened 1 year ago

bitfactory-sem-denbroeder commented 1 year ago

doltab currently doesnt have a systemd/unit file in order to consistently run the server in case of a reboot. i've created a sample service.sh which would allow for this file to be created and start the doltlab containers via systemd.

#!/bin/bash

set -e

# script should run as root
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

# get current dir and append start-doltlab.sh to it
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT="$DIR/start-doltlab.sh"

# create service file with script as ExecStart
unit="[Unit]
Description=%i DoltLab server
PartOf=docker.service
After=docker.service

[Service]
Type=oneshot
User=root
RemainAfterExit=true
WorkingDirectory=$DIR
ExecStart=$SCRIPT
ExecStop=/usr/local/bin/docker-compose down

[Install]
WantedBy=multi-user.target"
# test if unit is the same as the one present
if [ "$unit" = "$(cat /etc/systemd/system/doltlab.service)" ]; then
    echo "Service already exists at /etc/systemd/system/doltlab.service"
    exit 0
else
    echo "Creating service at /etc/systemd/system/doltlab.service"
    echo "$unit" > /etc/systemd/system/doltlab.service
fi
# reload deamon
systemctl daemon-reload
# enable service
systemctl enable doltlab.service
# start service
systemctl start doltlab.service
bitfactory-sem-denbroeder commented 1 year ago

This issue depends on #55 as systemd needs the env vars to start.