forked from clojure-grimoire/grimoire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit
More file actions
executable file
·103 lines (95 loc) · 1.81 KB
/
Copy pathinit
File metadata and controls
executable file
·103 lines (95 loc) · 1.81 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# chkconfig: 345 95 20
NAME=grimoire
VERSION=0.3.0
PID_DIR=/srv/www/grimoire.arrdem.com
PID_FILE=$PID_DIR/$NAME.pid
mkdir -p $PID_DIR
# returns 0 if PID in file is running, 1 if otherwise
process_running() {
pid=`cat "$PID_FILE" 2>/dev/null`
if [ "$pid" = '' ]
then
return 1 # PID file does not exist
else
kill_report=`kill -0 $pid 2>&1`
if [ "$kill_report" = '' ]
then
return 0
else
echo "Stale PID file exists at $PID_FILE"
return 1
fi
fi
}
start() {
if process_running
then
echo "$NAME is already running as process `cat $PID_FILE`."
exit 1
fi
echo "Starting $NAME"
lein serve &> grimoire.log &
PID=$!
echo $PID > $PID_FILE
exit 0
}
stop() {
if ! process_running
then
echo "$NAME is not running."
else
echo "Shutting down $NAME"
kill `cat $PID_FILE`
ps -ax | grep "java -classpath /srv/www/grimoire.arrdem.com" | awk "{print \$1}" | xargs kill
rm $PID_FILE
fi
}
force-stop() {
if ! process_running
then
echo "$NAME is not running."
else
echo "Forcefully shutting down $NAME"
kill -9 `cat $PID_FILE`
rm $PID_FILE
fi
}
status() {
if process_running
then
echo "$NAME is running."
else
echo "$NAME is not running."
fi
exit 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
force-stop)
force-stop
;;
status)
status
;;
restart)
stop
sleep 5
start
;;
deploy)
stop
sleep 5
start
;;
*)
echo "Usage: "$NAME"d {start|stop|status|restart|force-stop}"
exit 1
;;
esac
exit $?