-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·74 lines (68 loc) · 1.34 KB
/
run.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
#!/bin/bash
# Go to the script's folder
cd "`dirname "$0"`"
# Define needed variables
if [ -z "$APP_NAME" ]; then
APP_NAME="Email bridge"
fi
if [ -z "$JAR_FILE" ]; then
JAR_FILE=`ls -1 ../../target/email-bridge-*-standalone.jar | head -1`
fi
if [ -z "$CFG_FILE" ]; then
CFG_FILE=config.properties
fi
if [ -z "$LOG_FILE" ]; then
LOG_FILE=app.log
fi
if [ -z "$PID_FILE" ]; then
PID_FILE=app.pid
fi
PID="`cat $PID_FILE 2>/dev/null`"
if [ -n "$PID" -a "$OSTYPE" = "cygwin" ]; then
PID="`ps | awk "{if (\\$4 == $PID) print \\$1}"`"
fi
function start() {
echo -n "Starting $APP_NAME: "
if [ -n "$PID" ]; then
echo "failed - process is running with PID $PID";
exit 2
fi
# Make sure both working folders are existent
mkdir inbox outbox >/dev/null 2>&1
# Run and daemonize application
nohup java -jar "$JAR_FILE" -f "$CFG_FILE" >"$LOG_FILE" 2>&1 &
echo "success"
}
function stop() {
echo -n "Stopping $APP_NAME: "
if [ -z "$PID" ]; then
echo "failed - process isn't running";
exit 3
fi
kill $PID
echo "success"
}
case "$1" in
start) start;;
stop) stop;;
restart)
if [ -n "$PID" ]; then
stop
sleep 2
PID=""
fi
start
;;
status)
if [ -z "$PID" ]; then
echo "$APP_NAME isn't running";
exit 3
fi
echo "$APP_NAME is running with PID $PID";
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0