aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NOTES.tmp5
-rwxr-xr-xbin/app-conf3
-rw-r--r--lib/common34
-rwxr-xr-xlibexec/app-cat-conf5
-rwxr-xr-xlibexec/app-operate6
-rwxr-xr-xlibexec/app-operator-pid142
-rwxr-xr-xtest/app-init.bats4
-rwxr-xr-xtest/data/app-a/hooks/post-install4
-rwxr-xr-x[-rw-r--r--]test/data/app-a/root/bin/app-a3
9 files changed, 136 insertions, 70 deletions
diff --git a/NOTES.tmp b/NOTES.tmp
index 1173e32..5798e61 100644
--- a/NOTES.tmp
+++ b/NOTES.tmp
@@ -14,3 +14,8 @@ app init [-d directory] <resolver> <resolver args>
resolver/maven -r <repository url> <artifact id>
app list - lists all applications available under the specified directory
+
+
+TODO:
+* tab => spaces
+* camelCase => snake_case
diff --git a/bin/app-conf b/bin/app-conf
index d281740..3cf0383 100755
--- a/bin/app-conf
+++ b/bin/app-conf
@@ -86,7 +86,8 @@ usage() {
exit 1
}
-file=".app/config"
+app_home=${APP_HOME-.}
+file="$app_home/.app/config"
if [ $# -gt 0 ]
then
diff --git a/lib/common b/lib/common
index d53f0cf..e90f77b 100644
--- a/lib/common
+++ b/lib/common
@@ -16,15 +16,16 @@ assert_is_app() {
esac
done
- if [ ! -d .app ]
+ local app_home=${APP_HOME-.}
+
+ if [ ! -d "$app_home/.app" ]
then
- echo "This is not an app, missing directory: '.app'" >&2
- exit 1
+ fatal "This is not an app, missing directory: .app"
fi
if [[ $check_link == yes ]]
then
- if [ ! -e current ]
+ if [ ! -e "$app_home/current" ]
then
fatal "Missing 'current' link." >&2
fi
@@ -32,7 +33,7 @@ assert_is_app() {
if [[ $version != "" ]]
then
- if [[ ! -d versions/$version ]]
+ if [[ ! -d "$app_home/versions/$version" ]]
then
fatal "No such version: $version"
fi
@@ -160,17 +161,19 @@ run_app() {
done
local bin=$1; shift
- local e=`app-cat-conf -f .app/config -n "env\..*" | cut -f 2- -d .`
+ local e=`app-cat-conf -n "env\..*" | cut -f 2- -d .`
+
+ local app_home=`pwd`
(
- if [[ $version == "" ]]
- then
- assert_is_app
- cd current
- else
- assert_is_app -v "$version"
- cd "versions/$version"
- fi
+ if [[ $version == "" ]]
+ then
+ assert_is_app
+ cd current
+ else
+ assert_is_app -v "$version"
+ cd "versions/$version"
+ fi
# This magically get the expansion of $u correct.
IFS="
@@ -182,7 +185,8 @@ run_app() {
PATH=/bin:/usr/bin \
$e \
PWD="$PWD" \
- APPSH_HOME=$APPSH_HOME \
+ APPSH_HOME="$APPSH_HOME" \
+ APP_HOME="$app_home" \
$bin "$@"
local ret=$?
set +x
diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf
index 857ecaf..c75955b 100755
--- a/libexec/app-cat-conf
+++ b/libexec/app-cat-conf
@@ -40,9 +40,10 @@ done
if [[ $use_default_files == yes ]]
then
- if [ -r ".app/config" ]
+ app_home=${APP_HOME-.}
+ if [ -r "$app_home/.app/config" ]
then
- files+=(".app/config")
+ files+=("$app_home/.app/config")
fi
files+=(${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config})
diff --git a/libexec/app-operate b/libexec/app-operate
index 452f658..5fa939d 100755
--- a/libexec/app-operate
+++ b/libexec/app-operate
@@ -11,15 +11,13 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd)
assert_is_app
method="$1"; shift
-set -x
bin=`app-conf get app.operator`
bin=${bin:-$APPSH_HOME/libexec/app-operator-pid}
if [ ! -x "$bin" ]
then
- echo "Invalid executable: $bin" >&2
- exit 1
+ fatal "Invalid executable: $bin" >&2
fi
-run_app "$bin" "$@"
+run_app "$bin" "$method" "$@"
diff --git a/libexec/app-operator-pid b/libexec/app-operator-pid
index a0ff097..6aedb03 100755
--- a/libexec/app-operator-pid
+++ b/libexec/app-operator-pid
@@ -1,7 +1,5 @@
#!/bin/bash -e
-#!/bin/bash
-
set -e
set -u
@@ -10,31 +8,6 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd)
. $APPSH_HOME/lib/common
# HEADER END
-pid_file=$APPSH_APPS/.app/var/pid/$APPSH_NAME-$APPSH_INSTANCE.pid
-bin=`get_conf $APPSH_APPS $APPSH_NAME $APPSH_INSTANCE app.bin`
-
-cd $APPSH_APPS/$APPSH_NAME/$APPSH_INSTANCE/current
-
-if [ -z "$bin" ]
-then
- echo "Missing required configuration: app.bin." >&2
- exit 1
-fi
-
-if [ ! -r "$bin" ]
-then
- echo "No such file: $bin" >&2
- exit 1
-fi
-
-chmod +x "$bin"
-
-PID=
-if [ -r $pid_file ]
-then
- PID="`cat $pid_file`"
-fi
-
do_status() {
if [ -z "$PID" ]
then
@@ -49,7 +22,46 @@ do_status() {
fi
}
-method_start() {
+find_launcher() {
+ launcher=`app-conf get app.launcher`
+
+ if [ ! -z "$launcher" ]
+ then
+ if [ ! -r "$launcher" ]
+ then
+ fatal "No such file: $launcher" >&2
+ fi
+ else
+ # Search for the launcher
+ if [ -d bin ]
+ then
+ launcher=`grep_path ".*" bin`
+
+ # This will happen if grep_path returns multiple files.
+ # As we don't know which to choose, we'll fail.
+ if [ ! -x "$launcher" ]
+ then
+ launcher=""
+ fi
+ fi
+ fi
+
+ if [[ $launcher == "" ]]
+ then
+ fatal "No launcher configured (app.launcher), could not find a single executable to run." >&2
+ fi
+
+ if [[ ! -x $launcher ]]
+ then
+ fatal "Launcher not executable: $launcher" >&2
+ fi
+
+ echo $launcher
+}
+
+command_start() {
+ launcher=`find_launcher`
+
case `do_status` in
running)
echo "The application is already running as $PID."
@@ -57,7 +69,8 @@ method_start() {
;;
esac
- $bin <&- 1<&- 2<&- &
+ echo "Starting app with $launcher, pwd=`pwd`"
+ $launcher <&- 1<&- 2<&- &
PID=$!
echo "Application launched as $PID"
@@ -66,7 +79,7 @@ method_start() {
return 0
}
-method_stop() {
+command_stop() {
case `do_status` in
stopped)
echo "The application not running."
@@ -74,46 +87,83 @@ method_stop() {
;;
crashed)
echo "The application crashed. Was running as $PID"
- # TODO: should this remove the PID file?
- # That makes it possible to run "stop" to stop "status" from showing "crashed"
+ # TODO: should this remove the PID file? That makes it
+ # possible to run "stop" to stop "status" from showing
+ # "crashed". Perhaps just a "clear" goal to clear the pid file.
exit 1
;;
esac
- signal="-9"
- echo -n "Sending kill $signal to $PID, waiting for shutdown"
- kill $signal $PID
+ echo -n "Sending kill TERM to $PID, waiting for shutdown"
+ kill -TERM $PID
- while [ "`do_status`" == "running" ]
+ for i in {1..10}
do
+ if [ "`do_status`" != "running" ]
+ then
+ PID=
+ break
+ fi
+
sleep 1
- echo -n "."
+ echo -n .
done
+ if [[ $PID != "" ]]
+ then
+ echo "This is taking too long, sending KILL to $PID "
+ kill -KILL $PID
+
+ while [ "`do_status`" == "running" ]
+ do
+ sleep 1
+ echo -n .
+ done
+ fi
+
echo " OK"
rm -f $pid_file
return 0
}
-method_status() {
+command_status() {
case `do_status` in
running)
- echo "$APPSH_NAME/$APPSH_INSTANCE is running as $PID"
+ echo "Running as $PID"
;;
stopped)
- echo "$APPSH_NAME/$APPSH_INSTANCE is not running"
+ echo "Not running"
;;
crashed)
- echo "$APPSH_NAME/$APPSH_INSTANCE crashed. Was running as $PID"
+ echo "Crashed. Was running as $PID"
;;
esac
}
-case "$APPSH_METHOD" in
- start) method_start ;;
- stop) method_stop ;;
- status) method_status ;;
- *) exit 1 ;;
+APP_HOME=${APP_HOME-}
+
+if [[ $APP_HOME == "" ]]
+then
+ fatal "\$APP_HOME has to be set."
+fi
+
+pid_file=$APP_HOME/.app/pid
+
+PID=
+if [ -r $pid_file ]
+then
+ PID="`cat $pid_file`"
+fi
+
+command="$1"
+
+case "$command" in
+ start|stop|status)
+ command_$command
+ ;;
+ *)
+ fatal "Invalid command: $command"
+ ;;
esac
exit $?
diff --git a/test/app-init.bats b/test/app-init.bats
index 10edc63..df3919e 100755
--- a/test/app-init.bats
+++ b/test/app-init.bats
@@ -38,7 +38,9 @@ load utils
eq '${lines[3]}' "Unpacking..."
match '${lines[4]}' "Creating current symlink for version 1.0-.*"
eq '${lines[5]}' "Post install"
- eq '${#lines[*]}' 6
+ eq '${#lines[*]}' 6
is_directory "my-app/.app"
+ # Created by post-install
+ is_directory "my-app/logs"
}
diff --git a/test/data/app-a/hooks/post-install b/test/data/app-a/hooks/post-install
index 99ad974..c548ad7 100755
--- a/test/data/app-a/hooks/post-install
+++ b/test/data/app-a/hooks/post-install
@@ -3,3 +3,7 @@
set -u
echo "Post install"
+
+[ -d ../../logs ] || mkdir ../../logs
+
+ln -s ../../../logs root/logs
diff --git a/test/data/app-a/root/bin/app-a b/test/data/app-a/root/bin/app-a
index 98d98cd..d332993 100644..100755
--- a/test/data/app-a/root/bin/app-a
+++ b/test/data/app-a/root/bin/app-a
@@ -1,8 +1,9 @@
#!/bin/bash
-#cd $APPSH_INSTANCE_HOME
me=`basename $0`
+trap 'echo Signalled >> logs/$me.log; exit 0' TERM INT QUIT
+
env | grep TEST_PROPERTY >> logs/$me.env
echo "Starting" >> logs/$me.log