Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit a3c4c91

Browse files
author
Eric Meyer
committed
Simplifies process of setting up init.d script. Startup options are largely specified in datatool.properties. See init-script/README for detailed instructions. Removes use of jakarta-commons-daemon (jsvc).
1 parent 00c7f39 commit a3c4c91

File tree

13 files changed

+467
-367
lines changed

13 files changed

+467
-367
lines changed

.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
<classpathentry kind="lib" path="lib/hibernate/hibernate-validator-4.0.2.GA.jar"/>
102102
<classpathentry kind="lib" path="lib/dom4j-1.6.1/dom4j-1.6.1.jar" sourcepath="lib/dom4j-1.6.1/dom4j-1.6.1-sources.jar"/>
103103
<classpathentry kind="lib" path="lib/dom4j-1.6.1/jaxen-1.1-beta-6.jar"/>
104-
<classpathentry kind="lib" path="lib/jakarta/commons-daemon-1.0.2.jar" sourcepath="lib/jakarta/commons-daemon-1.0.2-sources.jar"/>
105104
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
106105
<classpathentry kind="lib" path="lib/test/derby-10.5.3.0.jar"/>
107106
<classpathentry kind="lib" path="lib/stax2-api-3.0.2.jar"/>

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@
218218
description="Build the distribution ZIP. Can set external.version if building from a tag.">
219219
<delete file="build.ant/discovery_datatool.zip"/>
220220
<zip destfile="build.ant/discovery_datatool-${external.version}.zip">
221-
<zipfileset prefix="discovery_datatool-${external.version}/" dir="stage" excludes="*.sh"/>
222-
<zipfileset prefix="discovery_datatool-${external.version}/" dir="stage" includes="*.sh" filemode="755"/>
221+
<zipfileset prefix="discovery_datatool-${external.version}/" dir="stage" excludes="bin/**,init-script/init.d/**,*.sh"/>
222+
<zipfileset prefix="discovery_datatool-${external.version}/" dir="stage" includes="bin/**,init-script/init.d/**,*.sh" filemode="755"/>
223223
<zipfileset prefix="discovery_datatool-${external.version}/" file="build.ant/discovery_datatool_standalone.jar"/>
224224
</zip>
225225
</target>
-14.7 KB
Binary file not shown.
-16 KB
Binary file not shown.

src/main/java/com/t11e/discovery/datatool/WebServerDaemon.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

stage/bin/datatool-spawner

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/bin/bash
2+
#
3+
# Script called from the discovery_datatool init script that runs a new
4+
# datatool in the background, storing the pid and piping the output
5+
# to a log file.
6+
#
7+
8+
set -e
9+
10+
#
11+
# Sanity check input variables
12+
#
13+
14+
if [ -z "$RELEASE_DIR" ]; then
15+
echo "RELEASE_DIR must be set" >&2
16+
exit 1
17+
fi
18+
if [ ! -d "$RELEASE_DIR" ]; then
19+
echo "RELEASE_DIR must be a directory: $RELEASE_DIR" >&2
20+
exit 1
21+
fi
22+
if [ -z "$DATATOOL_DIR" ]; then
23+
echo "DATATOOL_DIR must be set" >&2
24+
exit 1
25+
fi
26+
if [ ! -d "$DATATOOL_DIR" ]; then
27+
echo "DATATOOL_DIR must be a directory: $DATATOOL_DIR" >&2
28+
exit 1
29+
fi
30+
31+
# rotate logs
32+
function log_rotate {
33+
LOG_NAME=$1
34+
LOG_MAX=${2:- 30}
35+
LOG_NUM=$LOG_MAX
36+
while [ $LOG_NUM -ge 0 ]; do
37+
if [ $LOG_NUM -eq 0 ]; then
38+
SOURCE="$LOG_NAME"
39+
else
40+
SOURCE="$LOG_NAME.$LOG_NUM"
41+
fi
42+
if [ $LOG_NUM -eq $LOG_MAX ]; then
43+
TARGET=
44+
else
45+
TARGET="$LOG_NAME.$((LOG_NUM + 1))"
46+
fi
47+
if [ -f "$SOURCE" ]; then
48+
if [ -z "$TARGET" ]; then
49+
rm -f "$SOURCE"
50+
else
51+
mv -f "$SOURCE" "$TARGET"
52+
fi
53+
fi
54+
LOG_NUM=$((LOG_NUM - 1))
55+
done
56+
unset LOG_NAME LOG_MAX LOG_NUM
57+
}
58+
59+
# obtain discovery_datatool property values
60+
function get_property() {
61+
if [ $(grep -c "^ *$1 *=" datatool.properties ) -gt 0 ]; then
62+
grep "^ *$1 *=" datatool.properties | sed "s/^ *$1 *= *\([^ ]*\)/\1/"
63+
fi
64+
}
65+
#
66+
# Enter the datatool working directory and remain there for the
67+
# rest of this script.
68+
#
69+
70+
cd "$DATATOOL_DIR"
71+
72+
if [ ! -f datatool.properties ]; then
73+
echo "The datatool.properties file is missing from $(pwd)" >&2
74+
exit 1
75+
fi
76+
77+
#
78+
# Before we continue, make sure the datatool isn't already running
79+
#
80+
81+
if [ -f datatool.pid ]; then
82+
CMD=$(ps "$(cat datatool.pid)" | tail -n +2 | awk '{print $5}')
83+
if [ "$CMD" = "java" ]; then
84+
# There is a process with our last recorded pid that looks like
85+
# a java process, this is likely our datatool.
86+
echo "The datatool is already running with the pid: $(cat datatool.pid)" >&2
87+
exit 1
88+
fi
89+
unset CMD
90+
fi
91+
92+
#
93+
# Set some sensible defaults
94+
#
95+
96+
# jvm.cmd JVM to use
97+
JVM_CMD="$(get_property jvm\\.cmd)"
98+
if [ -z "$JAVA_CMD" ]; then
99+
JVM_CMD="java"
100+
fi
101+
102+
# jvm.args Arguments to pass to the jvm
103+
JVM_ARGS="$(get_property jvm\\.args)"
104+
if [ -z "$JVM_ARGS" ]; then
105+
JVM_ARGS="-showversion"
106+
fi
107+
108+
LOGGING_ARGS="$(get_property jvm\\.logging)"
109+
if [ -z "$LOGGING_ARGS" ]; then
110+
LOGGING_PROPERTIES="$RELEASE_DIR"/logging.properties
111+
if [ -f "$DATATOOL_DIR"/logging.properties ]; then
112+
LOGGING_PROPERTIES="$DATATOOL_DIR"/logging.properties
113+
fi
114+
LOGGING_ARGS="-Djava.util.logging.config.file=$LOGGING_PROPERTIES"
115+
unset LOGGING_PROPERTIES
116+
fi
117+
118+
# jvm.memory = Maximum amount of memory (in MB) the engine can use
119+
JVM_MEMORY="$(get_property jvm\\.memory)"
120+
if [ -n "$JVM_MEMORY" ]; then
121+
JVM_ARGS="$JVM_ARGS -Xmx${JVM_MEMORY}m"
122+
fi
123+
unset JVM_MEMORY
124+
125+
126+
datatool_http_port=$(get_property http_port)
127+
datatool_bind_address=$(get_property bind_address)
128+
datatool_https_port=$(get_property https_port)
129+
datatool_keystore_file=$(get_property keystore_file)
130+
datatool_keystore_pass=$(get_property keystore_pass)
131+
datatool_key_pass=$(get_property key_pass)
132+
datatool_truststore_file=$(get_property truststore_file)
133+
datatool_truststore_pass=$(get_property truststore_pass)
134+
135+
# Build command line arguments
136+
if [ -n "$datatool_bind_address" ]; then
137+
DATATOOL_ARGS="$DATATOOL_ARGS --bind-address $datatool_bind_address"
138+
fi
139+
if [ -n "$datatool_http_port" ]; then
140+
DATATOOL_ARGS="$DATATOOL_ARGS --port $datatool_http_port"
141+
fi
142+
if [ -n "$datatool_https_port" ]; then
143+
DATATOOL_ARGS="$DATATOOL_ARGS --https-port $datatool_https_port"
144+
fi
145+
if [ -n "$datatool_keystore_file" ]; then
146+
DATATOOL_ARGS="$DATATOOL_ARGS --keystore-file $datatool_keystore_file"
147+
fi
148+
if [ -n "$datatool_keystore_pass" ]; then
149+
DATATOOL_ARGS="$DATATOOL_ARGS --keystore-pass $datatool_keystore_pass"
150+
fi
151+
if [ -n "$datatool_key_pass" ]; then
152+
DATATOOL_ARGS="$DATATOOL_ARGS --key-pass $datatool_key_pass"
153+
fi
154+
if [ -n "$datatool_truststore_file" ]; then
155+
DATATOOL_ARGS="$DATATOOL_ARGS --truststore-file $datatool_truststore_file"
156+
fi
157+
if [ -n "$datatool_truststore_pass" ]; then
158+
DATATOOL_ARGS="$DATATOOL_ARGS --truststore-pass $datatool_truststore_pass"
159+
fi
160+
161+
162+
mkdir -p log
163+
164+
log_rotate log/datatool.out
165+
166+
#
167+
# Finally run the datatool, storing the pid
168+
#
169+
170+
rm -f datatool.pid datatool.state
171+
"$JVM_CMD" $JVM_ARGS $JAVA_OPTIONS $LOGGING_ARGS \
172+
-jar "$RELEASE_DIR"/discovery_datatool_standalone.jar $DATATOOL_ARGS \
173+
>& log/datatool.out &
174+
echo $! >datatool.pid

0 commit comments

Comments
 (0)