-
Notifications
You must be signed in to change notification settings - Fork 0
/
rctl
executable file
·53 lines (44 loc) · 1.31 KB
/
rctl
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
#!/bin/sh
set -e
TARGET=x86_64-unknown-linux-gnu
FLAGS=--features="place-bets"
MODE=debug
USER=aladdin
HOST=46.101.244.208
DIR=\~
MAIN=aladdin
LOG_FILE=aladdin.log
ENV="RUST_LOG=${RUST_LOG:=aladdin=info} RUST_BACKTRACE=1 TZ='Europe/Moscow'"
if [ $MODE == release ]; then
FLAGS="--release $FLAGS"
fi
function remote {
ssh -t "$USER@$HOST" "$1"
}
STATUS_CMD="start-stop-daemon --status --chdir $DIR --exec $MAIN"
START_CMD="$ENV start-stop-daemon --start --oknodo --no-close --background --chdir $DIR --exec $MAIN > $LOG_FILE 2>&1"
STOP_CMD="start-stop-daemon --stop --oknodo --retry 10 --chdir $DIR --exec $MAIN"
LOG_CMD="less -R +F $LOG_FILE"
case "$1" in
deploy)
cargo build --target=$TARGET $FLAGS
scp "target/$TARGET/$MODE/aladdin" "$USER@$HOST":~
;;
status)
set +e
remote "$STATUS_CMD"
case "$?" in
0) echo 'Aladdin is running' ;;
1|3) echo 'Aladdin is not running' ;;
4) echo 'Unable to determine status' ;;
esac
;;
log) remote "$LOG_CMD" ;;
start) remote "$START_CMD" ;;
stop) remote "$STOP_CMD" ;;
restart) remote "$STOP_CMD && $START_CMD" ;;
fetch-log) scp $USER@$HOST:$DIR/$LOG_FILE . ;;
*)
echo "Usage: "$1" {deploy|log|status|start|stop|restart|fetch-log}"
exit 1
esac