forked from datastax/cla-enforcer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cla-manager-staging.sh
executable file
·84 lines (74 loc) · 1.89 KB
/
cla-manager-staging.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
#!/bin/bash
APP_DIR=~/cla-enforcer
APP_BIN=$APP_DIR/bin/cla-enforcer
APP_LOG=$APP_DIR/logs/app-staging.log
APP_PID=$APP_DIR/app-staging.pid
APP_ENV=$APP_DIR/.env.staging
PUMA_PORT=5005
# Charger le profil bash
source ~/.bash_profile
start() {
if [ -f $APP_PID ] && kill -0 $(cat $APP_PID); then
echo "Application is already running"
exit 1
fi
echo "Starting application..."
cd $APP_DIR
bundle exec dotenv -f $APP_ENV $APP_BIN > $APP_LOG 2>&1 &
echo $! > $APP_PID
echo "Application started with PID $(cat $APP_PID)"
}
stop() {
if [ ! -f $APP_PID ] || ! kill -0 $(cat $APP_PID); then
echo "Application is not running"
exit 1
fi
echo "Stopping application..."
# Kill the main application process
kill -9 $(cat $APP_PID)
rm -f $APP_PID
# Kill only the Puma processes listening on the specified port
PUMA_PIDS=$(lsof -i tcp:$PUMA_PORT -t)
if [ ! -z "$PUMA_PIDS" ]; then
echo "Stopping Puma processes on port $PUMA_PORT..."
kill -9 $PUMA_PIDS
echo "Puma processes on port $PUMA_PORT stopped"
fi
echo "Application stopped"
}
restart() {
stop
start
}
status() {
if [ -f $APP_PID ] && kill -0 $(cat $APP_PID); then
echo "Application is running with PID $(cat $APP_PID)"
else
echo "Application is not running"
fi
# Check for Puma processes listening on the specified port
PUMA_PIDS=$(lsof -i tcp:$PUMA_PORT -t)
if [ ! -z "$PUMA_PIDS" ]; then
echo "Puma processes are running on port $PUMA_PORT with PIDs: $PUMA_PIDS"
else
echo "No Puma processes are running on port $PUMA_PORT"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac