-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrestart.sh
More file actions
executable file
·62 lines (52 loc) · 1.28 KB
/
restart.sh
File metadata and controls
executable file
·62 lines (52 loc) · 1.28 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
#!/usr/bin/env bash
BASE_DIR=`dirname $0`
PIDFILE_NAME="poopvolcano.pid"
PIDFILE="$BASE_DIR/$PIDFILE_NAME"
CMD="nohup ./app.js"
function log() {
local LEVELS=("DEBUG" "INFO" "WARNING" "ERROR")
local LEVEL="INFO"
local MESSAGE="$@"
local STAMP=$(date +'%m/%d/%y -- %H:%M:%S')
if [[ "$#" == "0" ]]; then
echo "ERROR: You're passing nothing to log!"
exit 1
elif [[ "$#" > "1" ]]; then
local MAYBE_LEVEL=$1
# See if the first param names a level when we have more params
(for level in ${LEVELS[@]};
do [[ "$level" == "$MAYBE_LEVEL" ]] && exit 1;
done; exit 0;
) || {
# Found a known level
LEVEL="$MAYBE_LEVEL";
shift;
MESSAGE="$@"
}
fi
echo "$STAMP [$LEVEL]: $MESSAGE";
};
function start() {
log "DEBUG" "$>" "$CMD"
$CMD &
PID="$!"
log "DEBUG" "PID: $PID"
echo "$PID" > "$PIDFILE"
};
# Prepare
cd $BASE_DIR
log "Operating in $BASE_DIR"
# Kill or warn
if [[ -f "$PIDFILE" ]]; then
PID=`cat $PIDFILE`
log "FOUND PID: $PID"
kill "$PID" && {
log "Killed process at $PID"
} || {
log "WARNING" "No process existed at $PID"
}
else
log "WARNING" "No PID found at $PIDFILE"
fi
# [Re]Start
start