You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by vd...@apache.org on 2016/04/12 00:20:51 UTC
[5/7] incubator-quarks git commit: QUARKS-13 startapp.sh starts
applications passed on the command line
QUARKS-13 startapp.sh starts applications passed on the command line
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/57ab58c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/57ab58c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/57ab58c2
Branch: refs/heads/master
Commit: 57ab58c27c81e6c5b61bca3ef01da45e5d37104b
Parents: 9a67449
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 11:04:45 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:57:38 2016 -0700
----------------------------------------------------------------------
scripts/cron/startapp.sh | 56 +++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/57ab58c2/scripts/cron/startapp.sh
----------------------------------------------------------------------
diff --git a/scripts/cron/startapp.sh b/scripts/cron/startapp.sh
index 903010f..73500af 100755
--- a/scripts/cron/startapp.sh
+++ b/scripts/cron/startapp.sh
@@ -16,28 +16,17 @@
# limitations under the License.
#
-[ ! -n "${QUARKS:-}" ] && QUARKS=../..
-
-#
-# Application name identifies the running process. For the scope of this
-# script it is also the name of the main application class.
-#
-APP=TerminateAfterNTuples
-
-#
-# Command to start the application.
-#
-COMMAND="java -cp ${QUARKS}/samples/lib/quarks.samples.topology.jar \
-quarks.samples.topology.${APP}"
-
-
_usage() {
- echo -e "Usage: ${0} [dir] \n\
- Runs an application while saving its stdout to dir/${APP}.out, its stderr to dir/${APP}.err, and its process id to dir/${APP}.pid.\n\
- \n\
- This script starts the application only if it cannot find its pid. If the process id indicated by dir/${APP}.pid exists, then the script will not start the application.\n\
- \n\
- If dir is not specified, then the stdout, stderr, and pid files are saved into the current directory.\n\
+ echo -e "Usage: ${0} {classpath} {mainclass} [dir]\n\n\
+Runs a Java application while saving its stdout to dir/mainclass.out, its stderr to dir/mainclass.err, and its process id to dir/mainclass.pid.\n\
+\n\
+This script starts a Java application only if it cannot find its pid. If the process id specified by dir/mainclass.pid exists, then the script will not start the application.\n\
+\n\
+ classpath The application's class path.\n\
+ classname The name of the class to be launched.\n\
+ dir The directory where the process stdout, stderr and pid files are\n\
+ written. If dir is not specified, then the files are saved into\n\
+ the current directory.\n\
"
}
@@ -85,12 +74,21 @@ _error() {
}
-if [ "${1:-.}" == "--help" ]; then
+## Main script
+[ ! -n "${QUARKS:-}" ] && QUARKS=../..
+[ ! -n "${JAVA_HOME:-}" ] && _error "JAVA_HOME must be set"
+
+if [ $# -lt 2 ]; then
_usage
exit 1
fi
-out_dir=${1:-.}
+classpath=${1}
+main_class=${2}
+out_dir=${3:-.}
+
+# Command to start the application.
+command="${JAVA_HOME}/bin/java -cp ${classpath} ${main_class}"
if [[ ! -d ${out_dir} || ${out_dir:0:1} != '/' ]]; then
## out_dir as absolute path
@@ -98,21 +96,21 @@ if [[ ! -d ${out_dir} || ${out_dir:0:1} != '/' ]]; then
out_dir=$(_dirname ${out_dir})
fi
-pid_file=${out_dir}/${APP}.pid
-out_file=${out_dir}/${APP}.out
-err_file=${out_dir}/${APP}.err
+pid_file=${out_dir}/${main_class}.pid
+out_file=${out_dir}/${main_class}.out
+err_file=${out_dir}/${main_class}.err
pid=
-_get_pid $APP $pid_file
+_get_pid $main_class $pid_file
RC="$?"
[ $RC == "1" ] && _error "Cannot access pid file $pid_file"
if [ -z "$pid" ]; then
- ${COMMAND} >> $out_file 2>> $err_file &
+ $command >> $out_file 2>> $err_file &
pid="$!"
echo $pid >| $pid_file
echo -e "The program was restarted with command:\n\
-${COMMAND}\n\
+${command}\n\
Process id: $pid"
else
echo "The program's process id is $pid"