-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvps_deploy
executable file
·48 lines (40 loc) · 1.24 KB
/
vps_deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# This is used to switch to a directory and restart supervisor programs
# can be called from my machine like:
# ssh vultr ./vps/bin/vps_deploy switch_dir restart_programs run_command
#
# if restart_programs is -, then no programs are restarted
set -e
# shellcheck disable=SC1091
source "${HOME}/.bashrc"
# shellcheck disable=SC1091
source "${HOME}/vps/server.sh"
set -x
# this is setup the first time I login
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
declare SWITCH_DIR RESTART_PROGRAMS_RAW RUN_COMMAND
SWITCH_DIR="${1?Pass the directory to switch to as the first argument}"
RESTART_PROGRAMS_RAW="${2?Pass the programs to restart as the second argument}"
RUN_COMMAND="$3"
declare -a RESTART_PROGRAMS=()
# split by commas into array
if [[ "$RESTART_PROGRAMS_RAW" == '-' ]]; then
RESTART_PROGRAMS_RAW=""
fi
IFS=',' read -r -a RESTART_PROGRAMS <<<"$RESTART_PROGRAMS_RAW"
if [[ ! -d "$SWITCH_DIR" ]]; then
echo "Directory $SWITCH_DIR does not exist" >&2
exit 1
fi
cd "$SWITCH_DIR" || exit 1
if [[ -d .git ]]; then
git pull || true
fi
if [[ -n "$RUN_COMMAND" ]]; then
sh -c "$RUN_COMMAND"
fi
if [[ -n "$RESTART_PROGRAMS_RAW" ]]; then
super --ctl restart "${RESTART_PROGRAMS[@]}"
fi
[[ -n "$SKIP_LOGS" ]] && exit 0
timeout 60 logs || true