summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.app/lib/app-common10
-rw-r--r--.app/lib/app-conf28
-rw-r--r--.app/lib/app-instance28
-rw-r--r--.app/lib/app-operate6
-rwxr-xr-x.app/lib/pid-method4
-rwxr-xr-xapp17
-rw-r--r--docs/README.md21
-rwxr-xr-xtest/app-install.bats5
-rwxr-xr-xtest/it-install-remove.bats3
-rw-r--r--test/utils.bash4
10 files changed, 68 insertions, 58 deletions
diff --git a/.app/lib/app-common b/.app/lib/app-common
index 584e053..ade49c7 100644
--- a/.app/lib/app-common
+++ b/.app/lib/app-common
@@ -37,7 +37,7 @@ list_apps() {
filter_instnace=$1; shift
vars="$@"
- sort $BASEDIR/.app/var/list | while read line
+ sort $apps/.app/var/list | while read line
do
echo $line | (IFS=:; while read name instance version junk
do
@@ -78,13 +78,13 @@ find_current_version() {
name=$1
instance=$2
- if [ ! -L $BASEDIR/$name/$instance/current ]
+ if [ ! -L $apps/$name/$instance/current ]
then
return 0
fi
(
- cd $BASEDIR/$name/$instance
+ cd $apps/$name/$instance
ls -l current | sed -n "s,.* current -> versions/\(.*\)/root,\1,p"
)
}
@@ -93,13 +93,13 @@ find_versions() {
name=$1
instance=$2
- if [ ! -d $BASEDIR/$name/$instance/versions ]
+ if [ ! -d $apps/$name/$instance/versions ]
then
return 0
fi
(
- cd $BASEDIR/$name/$instance/versions
+ cd $apps/$name/$instance/versions
ls -1d *
)
}
diff --git a/.app/lib/app-conf b/.app/lib/app-conf
index c9204e9..4cf4b7f 100644
--- a/.app/lib/app-conf
+++ b/.app/lib/app-conf
@@ -15,12 +15,12 @@ format_conf() {
}
get_conf() {
- local BASEDIR=$1
+ local apps=$1
local name=$2
local instance=$3
local key=$4
local default=
- local file=$BASEDIR/$name/$instance/current/etc/app.conf
+ local file=$apps/$name/$instance/current/etc/app.conf
shift 4
@@ -47,10 +47,10 @@ get_conf() {
}
get_conf_all() {
- local BASEDIR=$1
+ local apps=$1
local name=$2
local instance=$3
- local file=$BASEDIR/$name/$instance/current/etc/app.conf
+ local file=$apps/$name/$instance/current/etc/app.conf
if [ ! -r "$file" ]
then
@@ -61,12 +61,12 @@ get_conf_all() {
}
get_conf_in_group() {
- local BASEDIR=$1
+ local apps=$1
local name=$2
local instance=$3
local group=$4
- get_conf_all "$BASEDIR" "$name" "$instance" | sed -n "s,^${group}\.\(.*\),\1,p"
+ get_conf_all "$apps" "$name" "$instance" | sed -n "s,^${group}\.\(.*\),\1,p"
}
assert_key() {
@@ -81,13 +81,13 @@ assert_key() {
}
conf_set() {
- local BASEDIR=$1
+ local apps=$1
local name=$2
local instance=$3
local key=$4
local value=$5
- local file=$BASEDIR/$name/$instance/current/etc/app.conf
+ local file=$apps/$name/$instance/current/etc/app.conf
assert_key "$key"
@@ -101,12 +101,12 @@ conf_set() {
}
conf_delete() {
- local BASEDIR=$1
+ local apps=$1
local name=$2
local instance=$3
local key=$4
- local file=$BASEDIR/$name/$instance/current/etc/app.conf
+ local file=$apps/$name/$instance/current/etc/app.conf
assert_key "$key"
@@ -118,7 +118,7 @@ method_conf_list() {
local name=$1; shift
local instance=$1; shift
- get_conf_all "$BASEDIR" "$name" "$instance" | format_conf
+ get_conf_all "$apps" "$name" "$instance" | format_conf
}
method_conf_usage() {
@@ -166,7 +166,7 @@ method_conf() {
exit 1
fi
- get_conf_in_group "$BASEDIR" "$name" "$instance" "$1" | format_conf
+ get_conf_in_group "$apps" "$name" "$instance" "$1" | format_conf
;;
set)
if [ $# -ne 2 ]
@@ -175,7 +175,7 @@ method_conf() {
exit 1
fi
- conf_set "$BASEDIR" "$name" "$instance" "$1" "$2"
+ conf_set "$apps" "$name" "$instance" "$1" "$2"
;;
delete)
if [ $# -ne 1 ]
@@ -184,7 +184,7 @@ method_conf() {
exit 1
fi
- conf_delete "$BASEDIR" "$name" "$instance" "$1"
+ conf_delete "$apps" "$name" "$instance" "$1"
;;
*)
if [ $# -eq 0 ]
diff --git a/.app/lib/app-instance b/.app/lib/app-instance
index 5c452d2..89102b5 100644
--- a/.app/lib/app-instance
+++ b/.app/lib/app-instance
@@ -32,7 +32,7 @@ resolve_snapshot() {
local zip_file=$1
echo "Resolving version $version..."
- metadata=$BASEDIR/.app/var/download/$groupId-$artifactId-$version-metadata.xml
+ metadata=$apps/.app/var/download/$groupId-$artifactId-$version-metadata.xml
base_url=$repo/$(echo $groupId | sed "s,\.,/,g")/$artifactId/$version
get $base_url/maven-metadata.xml $metadata
resolved_version=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $metadata`
@@ -147,7 +147,7 @@ method_install() {
resolve_snapshot
- zip_file=$BASEDIR/.app/var/download/$groupId-$artifactId-$resolved_version.zip
+ zip_file=$apps/.app/var/download/$groupId-$artifactId-$resolved_version.zip
download_artifact $zip_file
;;
@@ -191,7 +191,7 @@ method_install() {
echo "Unpacking..."
unzip -q -d $name/$instance/versions/$resolved_version $zip_file
- if [ ! -d $BASEDIR/$name/$instance/versions/$resolved_version/root ]
+ if [ ! -d $apps/$name/$instance/versions/$resolved_version/root ]
then
echo "Invalid zip file, did not contain a ./root directory." >&2
exit 1
@@ -210,7 +210,7 @@ method_install() {
set +e
env -i \
PATH=/bin:/usr/bin \
- APPSH_BASEDIR=$BASEDIR \
+ APPSH_APPS=$apps \
APPSH_HOME=$APPSH_HOME \
APPSH_NAME=$name \
APPSH_INSTANCE=$instance \
@@ -228,8 +228,8 @@ method_install() {
)
echo "Changing current symlink"
- rm -f $BASEDIR/$name/$instance/current
- ln -s versions/$resolved_version/root $BASEDIR/$name/$instance/current
+ rm -f $apps/$name/$instance/current
+ ln -s versions/$resolved_version/root $apps/$name/$instance/current
if [ -d $name/$instance/current/bin ]
then
@@ -239,12 +239,12 @@ method_install() {
)
fi
- if [ -r $BASEDIR/.app/var/list ]
+ if [ -r $apps/.app/var/list ]
then
- sed "/^$name:$instance/d" $BASEDIR/.app/var/list > $BASEDIR/.app/var/list.new
+ sed "/^$name:$instance/d" $apps/.app/var/list > $apps/.app/var/list.new
fi
- echo "$name:$instance:$version:$url" >> $BASEDIR/.app/var/list.new
- mv $BASEDIR/.app/var/list.new $BASEDIR/.app/var/list
+ echo "$name:$instance:$version:$url" >> $apps/.app/var/list.new
+ mv $apps/.app/var/list.new $apps/.app/var/list
}
method_set_current_usage() {
@@ -293,14 +293,14 @@ method_set_current() {
assert_is_instance method_set_current_usage "$name" "$instance" "no"
- if [ ! -d $BASEDIR/$name/$instance/versions/$version ]
+ if [ ! -d $apps/$name/$instance/versions/$version ]
then
echo "Invalid version: $version."
exit 1
fi
- rm -f $BASEDIR/$name/$instance/current
- ln -s versions/$version/root $BASEDIR/$name/$instance/current
+ rm -f $apps/$name/$instance/current
+ ln -s versions/$version/root $apps/$name/$instance/current
return 0
}
@@ -347,7 +347,7 @@ method_list() {
esac
done
- if [ ! -r $BASEDIR/.app/var/list ]
+ if [ ! -r $apps/.app/var/list ]
then
return
fi
diff --git a/.app/lib/app-operate b/.app/lib/app-operate
index e28df96..45e3da2 100644
--- a/.app/lib/app-operate
+++ b/.app/lib/app-operate
@@ -25,7 +25,7 @@ run_control() {
APPSH_INSTANCE_HOME=`pwd`
cd current
- bin=`get_conf $BASEDIR $name $instance app.method`
+ bin=`get_conf $apps $name $instance app.method`
if [ -z "$bin" ]
then
@@ -38,7 +38,7 @@ run_control() {
exit 1
fi
- e="`get_conf_in_group $BASEDIR $name $instance env`"
+ e="`get_conf_in_group $apps $name $instance env`"
# Set a default PATH which can be overridden by the application's settings
set +e
@@ -46,7 +46,7 @@ run_control() {
PATH=/bin:/usr/bin \
$e \
APPSH_METHOD=$method \
- APPSH_BASEDIR=$BASEDIR \
+ APPSH_APPS=$apps \
APPSH_HOME=$APPSH_HOME \
APPSH_NAME=$name \
APPSH_INSTANCE=$instance \
diff --git a/.app/lib/pid-method b/.app/lib/pid-method
index a3e9cff..55d74b8 100755
--- a/.app/lib/pid-method
+++ b/.app/lib/pid-method
@@ -2,11 +2,11 @@
set -u
-PID_FILE=$APPSH_BASEDIR/.app/var/pid/$APPSH_NAME-$APPSH_INSTANCE.pid
+PID_FILE=$APPSH_APPS/.app/var/pid/$APPSH_NAME-$APPSH_INSTANCE.pid
. $APPSH_HOME/.app/lib/app-conf
-bin=`get_conf $APPSH_BASEDIR $APPSH_NAME $APPSH_INSTANCE app.bin`
+bin=`get_conf $APPSH_APPS $APPSH_NAME $APPSH_INSTANCE app.bin`
if [ -z "$bin" ]
then
diff --git a/app b/app
index f02f11d..84f757d 100755
--- a/app
+++ b/app
@@ -16,15 +16,14 @@ done
APPSH_HOME=`dirname "$PRG"`
APPSH_HOME=`cd "$APPSH_HOME" && pwd`
-if [ -z "$BASEDIR" ]
+if [ -z "$APPSH_APPS" ]
then
- BASEDIR=`dirname $0`
- BASEDIR=`cd $BASEDIR; pwd`
+ apps=`dirname $0`
+ apps=`cd $apps; pwd`
fi
-export BASEDIR
-mkdir -p $BASEDIR/.app/var/pid
-mkdir -p $BASEDIR/.app/var/download
+mkdir -p $apps/.app/var/pid
+mkdir -p $apps/.app/var/download
method_usage() {
if [ -n "$1" ]
@@ -104,9 +103,9 @@ main() {
fi
case "$method" in
- instance) method_instance "$name" "$instance" "$@" ;;
- conf) method_conf "$name" "$instance" "$@" ;;
- operate) method_operate "$name" "$instance" "$@" ;;
+ instance) method_instance "$name" "$instance" "$@" ;;
+ conf) method_conf "$name" "$instance" "$@" ;;
+ operate) method_operate "$name" "$instance" "$@" ;;
*)
if [ -z "$method" ]
then
diff --git a/docs/README.md b/docs/README.md
index c3cb679..4649ce3 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -38,6 +38,9 @@ TODOs
* Support -h for all applicable methods to show the help/usage.
+* Rename "scripts/" to handlers or something similar. Perhaps just
+ remove it entirely.
+
Commands
--------
@@ -108,17 +111,25 @@ Directory Hierarchy
### Current
+App.sh is installed through cloning the git repository and/or
+unpacking a tarball from the git repository. The directory that
+contains app is known as $APPSH_HOME
+
App.sh related:
- ./app
+ ./ The root of an application set. Known as $APPSH_APPS
+ ./app The app script, symlinked from your git clone directory
./.app/lib bash libraries used by app.sh and methods
./.app/var runtime data
Applications:
- ./<name>/<instance>/
- current - symlink to the currently installed app
- versions/ - collection with all installed versions
- 1.0/
+ ./<name>/<instance>/ - Known as $APPSH_INSTANCE_HOME
+ current - symlink to the currently installed app
+ versions/ - collection with all installed versions
+ 1.0/ - A installed version. The zip file is unzipped here.
+ The current directory for scripts executing from scripts/
+ root/
+ scripts/
1.1/
2.0/
diff --git a/test/app-install.bats b/test/app-install.bats
index 7b80547..df77594 100755
--- a/test/app-install.bats
+++ b/test/app-install.bats
@@ -29,19 +29,18 @@ Changing current symlink" ]
-r file \
-u $BATS_TEST_DIRNAME/data/install-test-env.zip \
-n install-test-env -i prod -v 1.0
-
echo_lines
[ $status -eq 0 ]
[ "$output" = "Creating instance 'prod' for 'install-test-env'
Unpacking...
Running postinstall...
-APPSH_BASEDIR=$APPSH_BASEDIR
+APPSH_APPS=$APPSH_APPS
APPSH_HOME=$APPSH_HOME
APPSH_INSTANCE=prod
APPSH_NAME=install-test-env
APPSH_VERSION=1.0
PATH=/bin:/usr/bin
-PWD=$WORK/install-test-env/prod/versions/1.0
+PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0
SHLVL=1
_=/usr/bin/env
Postinstall completed successfully
diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats
index bba16d2..5eb9f46 100755
--- a/test/it-install-remove.bats
+++ b/test/it-install-remove.bats
@@ -18,13 +18,14 @@ load utils
can_not_read ".app/var/pid/$name-$instance.pid"
+ describe "Setting property"
app -n $name -i $instance conf set env.TEST_PROPERTY awesome
[ $status -eq 0 ]
describe "Starting $name/$instance"
app -n $name -i $instance operate start
- [ $status -eq 0 ]
echo_lines
+ [ $status -eq 0 ]
can_read .app/var/pid/$name-$instance.pid
describe "Stopping $name/$instance"
diff --git a/test/utils.bash b/test/utils.bash
index 6a6967f..cd21966 100644
--- a/test/utils.bash
+++ b/test/utils.bash
@@ -14,13 +14,13 @@ echo_lines() {
APPSH=$(pwd)/app
setup() {
- APPSH_BASEDIR=$BATS_TMPDIR/app.sh
+ APPSH_APPS=$BATS_TMPDIR/app.sh
APPSH_HOME=$(cd $BATS_TEST_DIRNAME/../..; echo `pwd`/app.sh)
+ APPSH_APPS_CANONICAL=$(cd -P $APPSH_APPS; pwd)
rm -rf $BATS_TMPDIR/app.sh
mkdir $BATS_TMPDIR/app.sh
cd $BATS_TMPDIR/app.sh
ln -s $APPSH
- WORK=$(cd -P $BATS_TMPDIR/app.sh; pwd)
}
mkzip() {