feat: add Makefile and systemd service for linux deployment
This commit is contained in:
48
Makefile
Normal file
48
Makefile
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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."
|
||||||
26
env-guard.service
Normal file
26
env-guard.service
Normal 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
|
||||||
Reference in New Issue
Block a user