-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun_psc.sh
More file actions
executable file
·53 lines (41 loc) · 1.3 KB
/
run_psc.sh
File metadata and controls
executable file
·53 lines (41 loc) · 1.3 KB
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
49
50
51
52
53
#!/usr/bin/env bash
# Shell settings
# fail on failed commands
# we can't fail on unset variables, because envirius uses them
set -e
# the exit status of a pipe is the last non-zero exit, or zero if all succeed
set -o pipefail
# Argument processing
if [ $# -lt 5 ]; then
echo "usage: $0 GoEnv CP|DP|TS CN Port RestartSeconds [OptArg...]"
exit 1
fi
PSC_SCRIPT_DIR=`dirname "$0"`
PSC_GOENV="$1"
shift
PSC_USR_UPPER=`echo "$1" | tr 'a-z' 'A-Z'`
PSC_USR_LOWER=`echo "$1" | tr 'A-Z' 'a-z'`
PSC_USR_CMD=`echo "$PSC_USR_LOWER" | head -c 1`
shift
PSC_CNAME="$1"
shift
PSC_PORT="$1"
shift
PSC_RESTART="$1"
shift
# Prepare to launch the command
[ -f "$HOME/.envirius/nv" ] && . ~/.envirius/nv
cd "$PSC_SCRIPT_DIR"/"$PSC_USR_UPPER"
# Once the loop is running, don't exit this script on a non-zero exit status
set +e
# Don't write anything to stdout or stderr in this loop: the kernel will terminate
# the shell if there is no terminal attached to it
while true; do
# Launch the command in the correct environment
nv do "$PSC_GOENV" \
"go run $PSC_USR_LOWER.go -$PSC_USR_CMD $PSC_CNAME -p $PSC_PORT $@" \
>> "$PSC_SCRIPT_DIR"/"$PSC_USR_LOWER.$PSC_CNAME".log 2>&1 \
|| echo "Exit $?" >> "$PSC_SCRIPT_DIR"/"$PSC_USR_LOWER.$PSC_CNAME".log
# Wait for relaunch
sleep "$PSC_RESTART"
done