Compare commits

..

2 Commits

Author SHA1 Message Date
Jose Luis Montañes Ojados
c1c4dc62fb feat: add update target to Makefile for server binary updates 2026-01-28 18:03:05 +01:00
Jose Luis Montañes Ojados
126ec47b30 feat: add Makefile and systemd service for linux deployment 2026-01-28 17:35:17 +01:00
2 changed files with 83 additions and 0 deletions

57
Makefile Normal file
View File

@@ -0,0 +1,57 @@
BINARY_NAME=env-guard-server
SERVICE_NAME=env-guard.service
INSTALL_DIR=/usr/local/bin
SYSTEMD_DIR=/etc/systemd/system
WORK_DIR=/var/lib/env-guard
.PHONY: all build build-linux clean install uninstall
all: build
build:
go build -o $(BINARY_NAME) ./cmd/server
# Cross-compilation for Linux (useful if running this on Windows/Mac)
build-linux:
GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME) ./cmd/server
clean:
rm -f $(BINARY_NAME)
install: build-linux
@echo "Installing server..."
mkdir -p $(INSTALL_DIR)
cp $(BINARY_NAME) $(INSTALL_DIR)/
chmod +x $(INSTALL_DIR)/$(BINARY_NAME)
@echo "Creating working directory..."
mkdir -p $(WORK_DIR)
# Copy initial data files if they exist locally and not on target,
# otherwise app will create default/empty ones based on its logic.
# if [ -f services.json ]; then cp -n services.json $(WORK_DIR)/; fi
# if [ -f history.json ]; then cp -n history.json $(WORK_DIR)/; fi
@echo "Installing systemd service..."
cp $(SERVICE_NAME) $(SYSTEMD_DIR)/
systemctl daemon-reload
systemctl enable $(SERVICE_NAME)
systemctl start $(SERVICE_NAME)
@echo "Service installed and started!"
uninstall:
@echo "Uninstalling..."
systemctl stop $(SERVICE_NAME) || true
systemctl disable $(SERVICE_NAME) || true
rm -f $(SYSTEMD_DIR)/$(SERVICE_NAME)
rm -f $(INSTALL_DIR)/$(BINARY_NAME)
systemctl daemon-reload
@echo "Uninstalled."
update:
@echo "Updating server..."
systemctl stop $(SERVICE_NAME)
cp $(BINARY_NAME) $(INSTALL_DIR)/
chmod +x $(INSTALL_DIR)/$(BINARY_NAME)
systemctl start $(SERVICE_NAME)
systemctl status $(SERVICE_NAME)
@echo "Server updated!"

26
env-guard.service Normal file
View File

@@ -0,0 +1,26 @@
[Unit]
Description=EnvGuard Server
After=network.target
[Service]
# User/Group: Run as root by default to ensure permission to write to /var/lib/env-guard
# You can change this to a specific user if preferred (e.g., User=envguard),
# but remember to 'chown -R envguard:envguard /var/lib/env-guard'
User=root
Group=root
# Path to the binary
ExecStart=/usr/local/bin/env-guard-server
# Directory where services.json and history.json will be stored
WorkingDirectory=/var/lib/env-guard
# Restart policy
Restart=always
RestartSec=5
# Environment variables if needed
# Environment=ENVGUARD_SECRET_TOKEN=your-secret-token
[Install]
WantedBy=multi-user.target