Files
cc/app/sbin/start/n8n
2025-08-11 05:16:34 -03:00

53 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
exec > /4server/data/startContainer.log 2>&1
echo "$(date '+%Y-%m-%d %H:%M') - startContainer $1"
CONTAINER_NAME="$1"
# Get the hostname of the machine
HOSTNAME=$(hostname)
mkdir -p /4server/data/${CONTAINER_NAME}/n8n
mkdir -p /4server/data/${CONTAINER_NAME}/data
sudo chmod 777 /4server/data/${CONTAINER_NAME}/n8n
sudo chmod 777 /4server/data/${CONTAINER_NAME}/data
# Stop the container if it exists
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "$(date '+%Y-%m-%d %H:%M') - stopping existing container $CONTAINER_NAME"
docker stop "$CONTAINER_NAME"
docker rm "$CONTAINER_NAME"
fi
docker run -d \
--name "$CONTAINER_NAME" \
-p 5678 \
--cap-add=SYS_ADMIN \
--security-opt seccomp=unconfined \
--restart=always \
-e N8N_HOST="${CONTAINER_NAME}.od8n.com" \
-e N8N_PORT=5678 \
-e N8N_PROTOCOL=https \
-e NODE_ENV=production \
-e WEBHOOK_URL="https://${CONTAINER_NAME}.od8n.com/" \
-e GENERIC_TIMEZONE="UTC-3" \
-v "/4server/data/${CONTAINER_NAME}/n8n:/home/node/.n8n" \
-v "/4server/data/${CONTAINER_NAME}/data:/data" \
--label "traefik.enable=true" \
--label "traefik.http.routers.${CONTAINER_NAME}.rule=Host(\`${CONTAINER_NAME}.od8n.com\`)" \
--label "traefik.http.routers.${CONTAINER_NAME}.entrypoints=web,websecure" \
--label "traefik.http.routers.${CONTAINER_NAME}.tls=true" \
--label "traefik.http.routers.${CONTAINER_NAME}.tls.certresolver=production" \
--label "traefik.http.services.${CONTAINER_NAME}.loadbalancer.server.port=5678" \
--network docker-compose_4projects \
n8nio/n8n:latest
echo "Started $1"