euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 5c8d0b24b711c9225e0fdd3bf7c00c3001bf2182 (patch)
parent a7f252cf3b9a2a37aad6b9c0d43ba3eb34da16cf
Author: Alex Karle <alex@karle.co>
Date:   Mon, 25 May 2020 21:12:27 -0400

make: Update release dest, check in restart script

This is the infamous "safe deployment" script I've been using for a
while, tuned up for the preprod vs prod deployment. It basically boils
down to using pgrep/pkill to kill the old server (if running, and if no
players are on the server), then starting the server at the right port.

So the general workflow is to run "make release" to deploy to preprod,
and to cut a prod release, you need to ssh into the server, replace
"prod-el" with "preprod-el" and then call "restart.sh" manually.

A future commit will trim down some of these steps... but for now I
wanted to check in the WIP so that it wasn't lost (if I jump VPS
providers any time soon).

Diffstat:
MMakefile | 4++--
Abin/restart.sh | 43+++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -33,8 +33,8 @@ build: .public.ts $(LIB_FILES) gloat.pl .PHONY: release release: build test - rsync -av --delete build/ www@euchre.live:/var/www/euchre-live/ - ssh www@euchre.live env FORCE=$(FORCE) sh /var/www/deploy.sh + rsync -av --delete build/ www@euchre.live:/var/www/preprod-el/ + ssh www@euchre.live env FORCE=$(FORCE) sh /var/www/restart.sh preprod .PHONY: clean clean: diff --git a/bin/restart.sh b/bin/restart.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# no more tmux for daemons +# A safe restart script to be run on the server +set -e +die() { + echo "$1" 1>&2 + exit 1 +} + +HOST=localhost + +restart() { + name="$1" + port="$2" + if pgrep -f "gloat.pl.*$port"; then + if [ -z "$FORCE" ]; then + curl -s $HOST:$port/stats | grep -q "0 Players" || die "Players on server" + fi + + printf "%s" "Killing old server... " + pkill -f "gloat.pl.*$port" + sleep 2 # not needed? + echo "Check!" + fi + + if [ $name = "preprod" ]; then + export PREPROD=1 + fi + + printf "%s" "Starting new server... " + $HOME/${name}-el/gloat.pl daemon -l http://*:$port >> /var/log/gloat/$name.log 2>&1 & + sleep 2 + echo "Check!" + + curl -s $HOST:$port/stats | grep "Server Start" +} + +# Decide which server to restart based on the first arg +case "$1" in + preprod) restart "preprod" 3001 ;; + prod) restart "prod" 3000 ;; + *) die "usage: restart.sh prod|preprod" ;; +esac