Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions prod-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ fix_git_remote_and_branch() {
}

fix_node_modules() {
if [ ! -d "$PROJECT_DIR/node_modules" ] || [ ! -f "$PROJECT_DIR/node_modules/.package-lock.json" ]; then
say "Installing dependencies with npm ci --omit=dev"
npm ci --omit=dev
if [ ! -d "$PROJECT_DIR/node_modules" ]; then
if [ -f "$PROJECT_DIR/package-lock.json" ]; then
say "Installing dependencies with npm ci --omit=dev"
npm ci --omit=dev
else
say "Installing dependencies with npm install --omit=dev (package-lock.json missing)"
npm install --omit=dev
fi
fi
}

Expand Down Expand Up @@ -247,8 +252,8 @@ fix_require_and_import_hints() {

ensure_logrotate_config() {
local conf
conf=$(cat <<'CONF'
/var/www/html/Runewager/logs/runewager*.log /var/www/html/Runewager/logs/crash.log {
conf=$(cat <<CONF
$LOG_DIR/runewager*.log $LOG_DIR/crash.log {
daily
size 5M
rotate 7
Expand All @@ -271,6 +276,11 @@ CONF
fi
fi

if [ -f "$LOGROTATE_FILE" ] && ! grep -Fq "$LOG_DIR/runewager*.log" "$LOGROTATE_FILE"; then
warn "Replacing $LOGROTATE_FILE to use detected log directory"
printf '%s\n' "$conf" > "$LOGROTATE_FILE"
fi

if [ -f "$LOGROTATE_FILE" ] && command -v logrotate >/dev/null 2>&1; then
if ! logrotate -d "$LOGROTATE_FILE" >/dev/null 2>&1; then
warn "logrotate dry-run failed for $LOGROTATE_FILE"
Expand All @@ -296,25 +306,25 @@ ensure_cron_fallback() {

ensure_systemd_service() {
local conf
conf=$(cat <<'CONF'
conf=$(cat <<CONF
[Unit]
Description=Runewager bot
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
WorkingDirectory=/var/www/html/Runewager
ExecStart=/var/www/html/Runewager/prod-run.sh
WorkingDirectory=$PROJECT_DIR
ExecStart=$PROJECT_DIR/prod-run.sh
User=runewager
Group=runewager
EnvironmentFile=/var/www/html/Runewager/.env
EnvironmentFile=$PROJECT_DIR/.env
Environment=NODE_ENV=production
Restart=always
RestartSec=5
KillSignal=SIGTERM
TimeoutStopSec=20
StandardOutput=append:/var/www/html/Runewager/logs/runewager-1.log
StandardOutput=append:$LOG_DIR/runewager-1.log
StandardError=inherit

[Install]
Expand All @@ -334,7 +344,10 @@ CONF
fi

local required=(
'EnvironmentFile=/var/www/html/Runewager/.env'
"WorkingDirectory=$PROJECT_DIR"
"ExecStart=$PROJECT_DIR/prod-run.sh"
"EnvironmentFile=$PROJECT_DIR/.env"
"StandardOutput=append:$LOG_DIR/runewager-1.log"
'Environment=NODE_ENV=production'
'Restart=always'
'RestartSec=5'
Expand Down