63 lines
1.7 KiB
Bash
Executable File
63 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# install_service.sh - Installs the inventory system as a systemd service
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "🚫 This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
echo "⚙️ Installing TFM aInventory as a Systemd service..."
|
|
|
|
# Detect working directory
|
|
WORKING_DIR="$(pwd)"
|
|
|
|
# Detect Docker binary
|
|
DOCKER_BIN=$(which docker)
|
|
if [ -z "$DOCKER_BIN" ]; then
|
|
echo "❌ Docker not found! Please install Docker first."
|
|
exit 1
|
|
fi
|
|
|
|
# Determine if we use 'docker compose' or legacy 'docker-compose'
|
|
if docker compose version >/dev/null 2>&1; then
|
|
DOCKER_CMD="$DOCKER_BIN"
|
|
COMP_VER="v2 (plugin)"
|
|
else
|
|
DOCKER_BIN=$(which docker-compose)
|
|
if [ -z "$DOCKER_BIN" ]; then
|
|
echo "❌ neither 'docker compose' nor 'docker-compose' found!"
|
|
exit 1
|
|
fi
|
|
DOCKER_CMD="$DOCKER_BIN"
|
|
COMP_VER="v1 (legacy)"
|
|
fi
|
|
|
|
echo "✅ Found $COMP_VER at $DOCKER_CMD"
|
|
|
|
# Create the final service file from template
|
|
TEMPLATE="inventory.service.template"
|
|
TARGET="/etc/systemd/system/inventory.service"
|
|
|
|
if [ ! -f "$TEMPLATE" ]; then
|
|
echo "❌ Template file $TEMPLATE not found in current directory!"
|
|
exit 1
|
|
fi
|
|
|
|
sed "s|__WORKING_DIR__|$WORKING_DIR|g; s|__DOCKER_BIN__|$DOCKER_CMD|g" "$TEMPLATE" > "$TARGET"
|
|
|
|
echo "📝 Service file created at $TARGET"
|
|
|
|
# Reload and enable
|
|
systemctl daemon-reload
|
|
systemctl enable inventory.service
|
|
|
|
echo ""
|
|
echo "🚀 TFM aInventory service installed and enabled!"
|
|
echo " Commands:"
|
|
echo " 👉 sudo systemctl start inventory"
|
|
echo " 👉 sudo systemctl status inventory"
|
|
echo " 👉 sudo systemctl stop inventory"
|
|
echo ""
|
|
echo "Note: The service is currently ENABLED to start on boot, but NOT started."
|
|
echo " Run 'sudo systemctl start inventory' to launch it now."
|