-
Notifications
You must be signed in to change notification settings - Fork 1
/
hath.sh
94 lines (85 loc) · 1.85 KB
/
hath.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
91
92
93
94
#!/bin/sh
# Author: avluis ([email protected])
# Package
PACKAGE="hath"
DNAME="Hentai@Home"
# Package Variables
HATH_DIR="/home/$PACKAGE/client"
HATH_JAR="HentaiAtHome.jar"
HATH="$HATH_DIR/$HATH_JAR"
HATH_ARGS="--use_more_memory --disable_logging"
PID_FILE="$HATH_DIR/hath"
LOG_FILE="$HATH_DIR/data/log_out"
ERROR_FILE="$HATH_DIR/data/log_err"
JAVA="/opt/jdk/bin/java"
JAVA_ARGS="-jar $HATH"
USER="hath"
# Exit if the java is not installed
[ -x "$JAVA" ] || exit 0
start_daemon (){
if [ -f "$HATH" ]; then
nohup $JAVA $JAVA_ARGS $HATH_ARGS > /dev/null 2>&1 &
PID=$!
echo "$PID" > "$PID_FILE".pid
exit 0
else
echo "Program not found, update location or script."
exit 1
fi
}
stop_daemon (){
kill `cat "$PID_FILE".pid`
wait_for_status 1 20 || kill -9 `cat "$PID_FILE".pid`
rm -f "$PID_FILE".pid
}
daemon_status (){
if [ -f "$PID_FILE".pid ] && kill -0 `cat "$PID_FILE".pid` > /dev/null 2>&1; then
return
fi
rm -f "$PID_FILE".pid
return 1
}
wait_for_status (){
counter=$2
while [ ${counter} -gt 0 ]; do
daemon_status
[ $? -eq $1 ] && return
let counter=counter-1
sleep 1
done
return 1
}
case $1 in
start)
if daemon_status; then
echo ${DNAME} is already running
else
echo Starting ${DNAME} ...
start_daemon
fi
;;
stop)
if daemon_status; then
echo Stopping ${DNAME} ...
stop_daemon
else
echo ${DNAME} is not running
fi
;;
status)
if daemon_status; then
echo ${DNAME} is running
exit 0
else
echo ${DNAME} is not running
exit 1
fi
;;
log)
echo ${LOG_FILE}
;;
*)
echo "Usage: $0 {start|stop|status|log}"
exit 1
;;
esac