64 lines
1.4 KiB
Bash
Executable File
64 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Exit immediately if a command exits with a non-zero status.
|
|
set -e
|
|
|
|
# set the local repo location
|
|
LOCAL_REPO="/home/mason/src/ente"
|
|
INSTALL_DIR="/usr/local/bin/"
|
|
LIB_DIR="/var/lib/museum/"
|
|
PORT=1098
|
|
|
|
cd $LOCAL_REPO/server
|
|
|
|
# sed command to replace `server.Run(":8080")` with `server.Run(":$PORT")`
|
|
sed -i "s/server.Run(\":8080\")/server.Run(\":$PORT\")/g" cmd/museum/main.go
|
|
|
|
/usr/local/go/bin/go build -o museum cmd/museum/main.go
|
|
|
|
sudo cp museum $INSTALL_DIR
|
|
|
|
# Create a new user and group named 'museum'
|
|
sudo groupadd -r museum || true
|
|
sudo useradd -r -g museum -d $LIB_DIR -s /sbin/nologin -c "museum user" museum || true
|
|
|
|
|
|
sudo mkdir -p $LIB_DIR
|
|
sudo cp -r migrations $LIB_DIR
|
|
sudo cp -r mail-templates $LIB_DIR
|
|
sudo cp -r configurations $LIB_DIR
|
|
sudo cp museum.yaml $LIB_DIR
|
|
sudo chown -R museum:museum $LIB_DIR
|
|
|
|
# Create a new systemd service file for the museum service
|
|
sudo tee /etc/systemd/system/museum.service > /dev/null <<EOL
|
|
[Unit]
|
|
Description=Museum Service
|
|
After=syslog.target
|
|
After=network.target
|
|
Wants=postgresql.service
|
|
After=postgresql.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=museum
|
|
Group=museum
|
|
WorkingDirectory=$LIB_DIR
|
|
ExecStart=$INSTALL_DIR/museum
|
|
Restart=always
|
|
WatchdogSec=30s
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOL
|
|
|
|
# Reload systemd manager configuration
|
|
sudo systemctl daemon-reload
|
|
|
|
# Start the museum service
|
|
sudo systemctl start museum
|
|
|
|
# Enable the museum service to start on boot
|
|
sudo systemctl enable museum
|
|
|