generated from veeso-dev/fe-gatsby-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.sh
executable file
·90 lines (71 loc) · 1.42 KB
/
next.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
cd "$(dirname "$0")" || exit 1
APP_NAME="next"
MONIT_SERVICE="next"
PIDFILE="/var/run/$APP_NAME.pid"
info() {
printf '%s\n' "${BOLD}${GREY}>${NO_COLOR} $*"
}
warn() {
printf '%s\n' "${YELLOW}! $*${NO_COLOR}"
}
error() {
printf '%s\n' "${RED}x $*${NO_COLOR}" >&2
}
completed() {
printf '%s\n' "${GREEN}✓${NO_COLOR} $*"
}
start() {
cp .env.production .env
nvm use 20
export NEXT_SHARP_PATH="$(pwd)/node_modules/sharp"
yarn && yarn build
info "starting $APP_NAME"
screen -S $APP_NAME -d -m yarn start
sleep 1
PID=$(ps aux | grep "SCREEN -S $APP_NAME" | head -n 1 | awk '{print $2}')
echo "$PID" > $PIDFILE
info "$APP_NAME started with PID $PID"
return 0
}
stop() {
info "stopping $APP_NAME"
PID=$(cat $PIDFILE)
if [ -z "$PID" ]; then
error "Could not find any PID for $APP_NAME"
return 1
fi
info "killing PID $PID"
kill $PID
return 0
}
reload() {
git pull origin main
sudo monit restart $MONIT_SERVICE
}
NODE=$(which node)
if [ -z "$NODE" ]; then
export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm use 20
fi
case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
stop
start
;;
"reload")
reload
;;
*)
"unknown operation $OP"
exit 1
;;
esac