-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.sh
executable file
·94 lines (80 loc) · 2.11 KB
/
service.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
#!/bin/bash
#
# service.sh - can start/stop/restart the zim annotation helper
#
# !!!: here, the file is removed
#LOG_FILE=$HOME/tmp/zim-annotationhelper.log
LOG_FILE=/tmp/zim-annotationhelper.log
PID_FILE=$HOME/.local/run/zim-annotationhelper.pid
PROJECTS=$HOME/Projects
PROJECT_DIR=$(dirname $(realpath "$0"))
MAIN_CLASS="meta.works.zim.annotationhelper.Main"
cd /
test -d ~/.local/run || mkdir ~/.local/run
function status()
{
if [ -r "$PID_FILE" ]
then
PID=$(cat $PID_FILE)
if grep -q java /proc/$PID/cmdline
then
echo 2>&1 "process $PID is running"
return 0
else
echo 2>&1 "process $PID is DEAD"
return 2
fi
else
echo 2>&1 "No pid file: $PID_FILE"
return 1
fi
}
function start()
{
if status
then
echo 1>&2 "ERROR: Already running..."
return
fi
# The order here is important, particularly the last entry (which is the one that would be built by mvn)
JAR=$PROJECT_DIR/zim-annotationhelper.jar
test -e $JAR || JAR=$PROJECT_DIR/zim-annotationhelper-1.0-SNAPSHOT-jar-with-dependencies.jar
test -e $JAR || JAR=$PROJECT_DIR/out/artifacts/zim_annotationhelper_jar/zim-annotationhelper.jar
test -e $JAR || JAR=$PROJECT_DIR/target/zim-annotationhelper-1.0-SNAPSHOT-jar-with-dependencies.jar
test -e $JAR || mvn package
# Uggh... can't have it deleted: java.util.MissingResourceException: Can't find bundle for base name dbusjava_localized, locale en_US
#JAR2=$HOME/tmp/zim-annotationhelper.jar
JAR2=/tmp/zim-annotationhelper.jar
cp -v "$JAR" "$JAR2"
mv -f "$LOG_FILE" "${LOG_FILE}.old" || true
D1=/usr/share/java/dbus-java
D2=/usr/lib/java
nohup java -cp $D1/dbus.jar:$D2/unix.jar:$D2/debug-disable.jar:"$JAR2" -Djava.library.path=/usr/lib64/libmatthew-java "$MAIN_CLASS" >> $LOG_FILE 2>&1 &
echo -n "$!" > "$PID_FILE"
sleep 0.5
status
}
function stop()
{
if [ -r "$PID_FILE" ]
then
pkill -F "$PID_FILE" java || true
#NB: This would kill the service script too.
#pkill -f zim-annotationhelper || true
rm -f "$PID_FILE"
else
echo 1>&2 "ERROR: Missing/unreadable pid file: $PID_FILE"
exit 1
fi
}
function restart()
{
if status
then
stop
fi
sleep "${1:-1}"
start
}
set -vexu
"$@"