From e694d9024cddf4dd54efd828927e3fd5e70b6c3a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Oct 2013 23:30:49 +0100 Subject: o Removing all old code (X files). o Making sure APPSH_HOME is 1) exported and, 2) always prepended to $PATH. o More documentation on what a zip file actually looks like and how to create hooks. --- app_completion | 4 +- bin/X-app-instance | 502 ------------------------------------------ bin/app-conf | 18 +- bin/app-foreach-app | 2 +- bin/app-init | 2 +- bin/app-ls-apps | 2 +- bin/app-restart | 2 +- bin/app-start | 2 +- bin/app-status | 2 +- bin/app-stop | 2 +- bin/app-upgrade | 2 +- docs/app.txt | 67 ++++-- lib/common | 8 +- lib/header | 2 +- libexec/app-cat-conf | 4 +- libexec/app-grep-path | 2 +- libexec/app-install-file | 2 +- libexec/app-operate | 2 +- libexec/app-operator-pid | 9 +- libexec/app-resolver-file | 9 +- libexec/app-resolver-maven | 2 +- libexec/app-run-hook | 2 +- libexec/app-set-version | 2 +- test/X-app-help.bats | 38 ---- test/X-app-install.bats | 50 ----- test/X-app-list-versions.bats | 28 --- test/X-app-list.bats | 102 --------- test/X-help.bats | 17 -- test/app-upgrade.bats | 8 +- 29 files changed, 98 insertions(+), 796 deletions(-) delete mode 100755 bin/X-app-instance delete mode 100755 test/X-app-help.bats delete mode 100755 test/X-app-install.bats delete mode 100755 test/X-app-list-versions.bats delete mode 100755 test/X-app-list.bats delete mode 100755 test/X-help.bats diff --git a/app_completion b/app_completion index 4e62bbc..55597c1 100644 --- a/app_completion +++ b/app_completion @@ -65,7 +65,7 @@ _complete_appsh() { then opts="-n $opts" fi - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 fi @@ -116,7 +116,7 @@ _complete_appsh() { ;; esac - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) set +x } diff --git a/bin/X-app-instance b/bin/X-app-instance deleted file mode 100755 index 02e3c0f..0000000 --- a/bin/X-app-instance +++ /dev/null @@ -1,502 +0,0 @@ -#!/bin/bash - -if [[ $APPSH_HOME == "" ]] -then - APPSH_HOME=`dirname "$0"` - APPSH_HOME=`cd "$APPSH_HOME/.." && pwd` -fi - -if [ -n "$APPSH_REPO" ] -then - repo="$APPSH_REPO" -else - repo="http://repo1.maven.org" -fi - -calculate_md5() { - local file="$1"; shift - - md5sum "$file" | cut -c 1-32 -} - -# TODO: support file:// repositories -# TODO: look in the local repository first -get() { - local url=$1 - local file=$2 - local exit - - curl -o $file $url -D curl.tmp - - exit=`grep "^HTTP/[0-9]\.[0-9] 200 .*" curl.tmp >/dev/null; echo $?` - head=`head -n 1 curl.tmp` - rm -f curl.tmp - if [ "$exit" != 0 ] - then - echo "Unable to download $url: $head" >&2 - exit 1 - fi -} - -resolve_snapshot() { - local groupId=$1; shift - local groupIdSlash=$1; shift - local artifactId=$1; shift - local version=$1; shift - - local metadata=$apps/.app/var/download/$groupId-$artifactId-$version-metadata.xml - local base_url=$repo/$groupIdSlash/$artifactId/$version - get $base_url/maven-metadata.xml $metadata - local resolved_version=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $metadata` - echo $resolved_version -} - -download_artifact() { - local file="$1"; shift - local url="$1"; shift - - echo "Downloading $url.md5" - get $url.md5 $file.md5 - local expected_md5="`cat $file.md5`" - - if [ -r $file ] - then - if [ "$expected_md5" == "`calculate_md5 $file`" ] - then - echo "Artifact already downloaded." - else - rm -f "$file" - fi - return 0 - fi - echo "Downloading artifact: $url" - get $url $file - - local actual_md5="`calculate_md5 $file`" - if [ "$expected_md5" == "$actual_md5" ] - then - echo "Artifact downloaded." - else - echo "Invalid checksum. Expected $expected_md5, got $actual_md5" >&2 - exit 1 - fi -} - -method_install_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: install <-r resolver> -u " >&2 - echo "" >&2 - echo "Install package from a Maven repository:" >&2 - echo " $0 [-n name] [-i instance] instance install -r maven -u groupId:artifactId:version" >&2 - echo "" >&2 - echo "Install package from a file:" >&2 - echo " $0 [-n name] [-i instance] instance install -r file -u file [-v version]" >&2 - echo "The version defaults to the current timestamp" >&2 - exit 1 -} - -method_install() { - local name="$1"; shift - local instance="$1"; shift - local version - local resolver - local url - local groupId - local artifactId - local zip_file - - - if [ $# -eq 0 ] - then - method_install_usage - fi - - while getopts "n:i:v:r:u:" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - r) - resolver=$OPTARG - ;; - u) - url=$OPTARG - ;; - \?) - method_install_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ -z "$name" ] - then - method_install_usage "Missing required argument: -i name." - fi - - if [ -z "$instance" ] - then - method_install_usage "Missing required argument: -i instance." - fi - - if [ -z "$resolver" ] - then - method_install_usage "Missing required option: -r resolver" - fi - - if [ -z "$url" ] - then - method_install_usage "Missing required option: -u url" - fi - - case "$resolver" in - maven) - url=`echo $url | tr ":" " "`; set -- $url - groupId=$1 - artifactId=$2 - version=$3 - - if [ -z "$groupId" -o -z "$artifactId" -o -z "$version" ] - then - method_install_usage "Invalid Maven url." - fi - - local groupIdSlash=$(echo $groupId | sed "s,\.,/,g") - if [ "`echo $version | sed -n s,.*-SNAPSHOT$,SNAPSHOT,p`" == "SNAPSHOT" ] - then - echo "Resolving version $version..." - local resolved_version=`resolve_snapshot $groupId $groupIdSlash $artifactId $version` - if [ -z "$resolved_version" ] - then - echo "Unable to resolve version." - exit 1 - fi - echo "Resolved version $version to $resolved_version" - else - resolved_version=$version - fi - - zip_file=$apps/.app/var/download/$groupId-$artifactId-$resolved_version.zip - artifact_url=$repo/$groupIdSlash/$artifactId/$version/$artifactId-$resolved_version.zip - - download_artifact "$zip_file" "$artifact_url" - ;; - file) - if [ ! -r "$url" ] - then - echo "Could not read file: $url" >&2 - exit 1 - fi - - # TODO: should the zip file be copied into download/ so that - # there's always a local copy? - zip_file=$url - - if [ -z "$version" ] - then - version=`TZ=UTC date +"%Y%m%d-%H%M%S"` - fi - - resolved_version=$version - ;; - *) - method_install_usage "Invalid resolver type: $resolver" - ;; - esac - - if [ -d $name/$instance/versions/$resolved_version ] - then - echo "Version $resolved_version is already installed" - exit 1 - fi - - if [ ! -d $name/$instance ] - then - echo "Creating instance '$instance' for '$name'" - mkdir -p $name/$instance - fi - - mkdir -p $name/$instance/versions/$resolved_version - - echo "Unpacking..." - unzip -q -d $name/$instance/versions/$resolved_version $zip_file - - if [ ! -d $name/$instance/versions/$resolved_version/root ] - then - echo "Invalid zip file, did not contain a ./root directory." >&2 - exit 1 - fi - - echo "Changing current symlink" - rm -f $apps/$name/$instance/current - ln -s versions/$resolved_version/root $apps/$name/$instance/current - - if [ -d $name/$instance/current/bin ] - then - ( - cd $name/$instance/current - find bin -type f | xargs chmod +x - ) - fi - - ( - cd $name/$instance/versions/$resolved_version - if [ -d scripts ] - then - find scripts | xargs chmod +x - fi - - if [ -x scripts/postinstall ] - then - echo "Running postinstall..." - cd root - set +e - env -i \ - PATH=/bin:/usr/bin \ - APPSH_APPS=$apps \ - APPSH_HOME=$APPSH_HOME \ - APPSH_NAME=$name \ - APPSH_INSTANCE=$instance \ - APPSH_VERSION=$resolved_version \ - ../scripts/postinstall - set -e - ret=`echo $?` - if [ "$ret" != 0 ] - then - echo "Postinstall failed!" - exit 1 - fi - echo "Postinstall completed successfully" - fi - ) - - if [ -r $apps/.app/var/list ] - then - sed "/^$name:$instance/d" $apps/.app/var/list > $apps/.app/var/list.new - fi - echo "$name:$instance:$version:$url" >> $apps/.app/var/list.new - mv $apps/.app/var/list.new $apps/.app/var/list -} - -method_set_current_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: set-current -v version" >&2 - exit 1 -} - -method_set_current() { - local name="$1"; shift - local instance="$1"; shift - local version - - if [ $# -eq 0 ] - then - method_set_current_usage - fi - - while getopts "n:i:v:" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - \?) - method_set_current_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ -z "$version" ] - then - echo "Missing required option -v version." >&2 - exit 1 - fi - - assert_is_instance method_set_current_usage "$name" "$instance" "no" - - if [ ! -d $apps/$name/$instance/versions/$version ] - then - echo "Invalid version: $version." - exit 1 - fi - - rm -f $apps/$name/$instance/current - ln -s versions/$version/root $apps/$name/$instance/current - - return 0 -} - -method_list_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: list [-n name] [-P field]" >&2 - echo "" - echo "List all installed applications:" >&2 - echo " list" >&2 - echo "" - echo "List all applications with the selected fields with parseable output:" >&2 - echo " list -P instance -P version -n foo" >&2 - exit 1 -} - -method_list() { - local filter_name="$1"; shift - local filter_instance="$1"; shift - local mode="pretty" - local vars - local filter_name - - while getopts "P:n:i:" opt - do - case $opt in - P) - mode="parseable" - vars="$vars $OPTARG" - ;; - n) - filter_name=$OPTARG - ;; - i) - filter_instance=$OPTARG - ;; - \?) - method_list_usage "Invalid option: -$OPTARG" - ;; - esac - done - - if [ ! -r $apps/.app/var/list ] - then - return - fi - - if [ $mode = "pretty" ] - then - printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version" - list_apps "$filter_name" "$filter_instance" name instance version | (IFS=:; while read name instance version - do - printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version" - done) - else - list_apps "$filter_name" "$filter_instance" $vars - fi -} - -method_list_versions_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: list-versions -n name -i instance [-P]" >&2 - exit 1 -} - -method_list_versions() { - local filter_name="$1"; shift - local instance="$1"; shift - local version - local mode="pretty" - - if [ $# -eq 0 ] - then - method_list_versions_usage - fi - - while getopts "n:i:P" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - v) - version=$OPTARG - ;; - P) - mode="parseable" - ;; - \?) - method_list_versions_usage "Invalid option: -$OPTARG" - ;; - esac - done - - assert_is_instance method_list_versions_usage "$name" "$instance" "no" - - if [ $mode = "pretty" ] - then - echo "Available versions for $name/$instance:" - fi - - find_versions $name $instance - - return 0 -} - -method_instance_usage() { - if [ -n "$1" ] - then - echo "Error:" $@ >&2 - fi - - echo "usage: $0 instance " >&2 - echo "" >&2 - echo "Available methods:" >&2 - echo " install - Installs an application" >&2 - echo " list - List all installed applications" >&2 - echo " list-versions - List all available versions for a single application" >&2 - echo " set-current - Set the current version" >&2 -} - -method_instance() { - local name="$1"; shift - local instance="$1"; shift - local method="$1" - - if [ $# -gt 0 ] - then - shift - fi - - case "$method" in - install) method_install "$name" "$instance" "$@" ;; - list) method_list "$name" "$instance" "$@" ;; - list-versions) method_list_versions "$name" "$instance" "$@" ;; - set-current) method_set_current "$name" "$instance" "$@" ;; - *) - if [ -z "$method" ] - then - method_instance_usage - else - method_instance_usage "Unknown method $method" - fi - ;; - esac - exit $? -} diff --git a/bin/app-conf b/bin/app-conf index 23b68f7..8f34b57 100755 --- a/bin/app-conf +++ b/bin/app-conf @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END @@ -22,8 +22,6 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) PATH=$APPSH_HOME/libexec:$PATH -key_expr="[a-zA-Z][_a-zA-Z0-9]*" - format_conf() { local IFS== while read key value @@ -34,13 +32,11 @@ format_conf() { } assert_valid_config_name() { - local name=$1 - - local x=`echo $name | sed -n "/^$key_expr\\.$key_expr$/p"` - if [ -z "$x" ] + local name=$1; shift + local x="^$key_expr\\.$key_expr$" + if [[ ! $name =~ $x ]] then - echo "Invalid name: $name" >&2 - exit 1 + fatal "Invalid name: $name" fi } @@ -64,7 +60,7 @@ conf_set() { echo "$name=$value" >> "$file.tmp" mv "$file.tmp" "$file" -} +}; shift conf_delete() { local file=$1; shift @@ -82,7 +78,7 @@ conf_import() { echo "Importing config from $src" app-cat-conf -f "$dst" -f "$src" > "$dst.tmp" - mv "$dst.tmp" "$dst" + mv "$dst.tmp" "$dst" } usage_text() { diff --git a/bin/app-foreach-app b/bin/app-foreach-app index 5b5b108..561656e 100755 --- a/bin/app-foreach-app +++ b/bin/app-foreach-app @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-init b/bin/app-init index 534a876..bc4a0b2 100755 --- a/bin/app-init +++ b/bin/app-init @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-ls-apps b/bin/app-ls-apps index 4adc274..86ca534 100755 --- a/bin/app-ls-apps +++ b/bin/app-ls-apps @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-restart b/bin/app-restart index 768aea0..d01e161 100755 --- a/bin/app-restart +++ b/bin/app-restart @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-start b/bin/app-start index be290ce..e1db3d5 100755 --- a/bin/app-start +++ b/bin/app-start @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-status b/bin/app-status index e36e1d6..e3b3b12 100755 --- a/bin/app-status +++ b/bin/app-status @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-stop b/bin/app-stop index 535af9e..c7c0ddb 100755 --- a/bin/app-stop +++ b/bin/app-stop @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/bin/app-upgrade b/bin/app-upgrade index 3c5f8dc..1a8329a 100755 --- a/bin/app-upgrade +++ b/bin/app-upgrade @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/docs/app.txt b/docs/app.txt index 9ab0ba7..487c9cd 100644 --- a/docs/app.txt +++ b/docs/app.txt @@ -16,31 +16,31 @@ DOCUMENTATION QUICK START ~~~~~~~~~~~ ------------------------------------------------------------------------- +--------------------------------------------------------------------- $ app init -d my-app maven org.example:my-app:1.0-SNAPSHOT $ cd my-app $ app start $ app conf set app.version 1.0 $ app upgrade $ app restart ------------------------------------------------------------------------- +--------------------------------------------------------------------- INSTALLING AN APPLICATION ~~~~~~~~~~~~~~~~~~~~~~~~~ This resolved and downloads an appliaction from a Maven repository: ------------------------------------------------------------------------- +--------------------------------------------------------------------- $ app init -d my-app maven org.example:my-app:1.0-SNAPSHOT ------------------------------------------------------------------------- +--------------------------------------------------------------------- By default it will download from the central repository, but this is not always what you want. To get it to use another repository give the `-r` option: ------------------------------------------------------------------------- +--------------------------------------------------------------------- $ app init -d my-app maven -f http://repo.example.org/snapshots org.example:my-app:1.0-SNAPSHOT ------------------------------------------------------------------------- +--------------------------------------------------------------------- UPGRADING AN APPLICATION ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -49,9 +49,9 @@ If your application is configured with the Maven resolver and the version is a SNAPSHOT version, you can use this to upgrade your application through a cron job: ------------------------------------------------------------------------- +--------------------------------------------------------------------- $ app upgrade ------------------------------------------------------------------------- +--------------------------------------------------------------------- With the resolver will try to resolve `app.version` to the latest version. If it's change it will automatically download and install the @@ -60,10 +60,10 @@ latest version. CHANGING VERSION OF AN APPLICATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ------------------------------------------------------------------------- +--------------------------------------------------------------------- $ app conf set app.version 1.0 $ app sync-version ------------------------------------------------------------------------- +--------------------------------------------------------------------- `app-sync-version` will first run the resolver to resolve the version and if that has changed, it will download and install the new version. @@ -71,10 +71,33 @@ and if that has changed, it will download and install the new version. CREATING APPS ------------- -TODO - -CREATING HOOKS -~~~~~~~~~~~~~~ +An "app" is in itself nothing more than a zip archive with a particular +layout. In the root of the zip archive there must be a directory called +`root`. You can also place a file called `app.config` at the root. The +config file will be imported into the app's configuration. It is also +possible to run appliations before and after appliations are installed +through hooks. These are placed in a `hooks` directory, also at the +root of the archive. + +To summarize, this is what an application zip archive looks like: + +--------------------------------------------------------------------- +/app.conf +/root +/root/bin +/root/bin/my-app +/root/repo/ +/root/repo/io +/root/repo/io/trygvis/ +/root/repo/io/trygvis/... +/hooks/ +/hooks/post-install +--------------------------------------------------------------------- + +If this looks familiar to RPMs, Debs or Pkg files, you're right. + +HOOKS +~~~~~ TODO @@ -83,10 +106,22 @@ CREATING LAUNCHERS Trick when you don't know why your app won't start: ------------------------------------------------------------------------- +--------------------------------------------------------------------- exec 1>/tmp/myapp.out exec 2>/tmp/myapp.err ------------------------------------------------------------------------- +--------------------------------------------------------------------- + +Make sure you _always_ use `exec` when spawning the actual app. This +makes sure that the pid operator records the correct PID. If you don't +do this the application will run, but will be reported as crashed when +you run 'app status'. + +If you can't use `exec` or the application demands to deamonize itself +(like Apache Httpd), you have to set the configuration option +`app.pid_management=launcher`. Then the launcher is responsible for +creating the PID file under $APP_HOME/.app/pid. You can create a +symlink to the actual PID file if you can't customize where the app +places the file. TODOs ----- diff --git a/lib/common b/lib/common index b52da43..369f0be 100755 --- a/lib/common +++ b/lib/common @@ -288,12 +288,18 @@ find_resolver() { grep_path "/app-resolver-$resolver_name$" "$PATH" | head -n 1 } +##################################################################### +# Values + +key_expr="[a-zA-Z][-_a-zA-Z0-9]*" + ##################################################################### # Common init # Add the app-* apps to PATH. They're added last to allow the user to # overload their implementations. -PATH=$PATH:$APPSH_HOME/bin:$APPSH_HOME/libexec +# Ideally we should parse the path here and remove duplicates. +PATH=$APPSH_HOME:$APPSH_HOME/bin:$APPSH_HOME/libexec:$PATH # Make sure that $HOME is present to prevent unbound errors HOME=${HOME:-} diff --git a/lib/header b/lib/header index 805e06e..876750f 100644 --- a/lib/header +++ b/lib/header @@ -3,6 +3,6 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf index 6e2567f..12d3afc 100755 --- a/libexec/app-cat-conf +++ b/libexec/app-cat-conf @@ -3,13 +3,11 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END -key_expr="[a-zA-Z][_a-zA-Z0-9]*" - files=() arg_files=() declare -a arg_files diff --git a/libexec/app-grep-path b/libexec/app-grep-path index fa6e5e5..bef44cd 100755 --- a/libexec/app-grep-path +++ b/libexec/app-grep-path @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/libexec/app-install-file b/libexec/app-install-file index db9432b..be445d9 100755 --- a/libexec/app-install-file +++ b/libexec/app-install-file @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/libexec/app-operate b/libexec/app-operate index 5fa939d..27727c8 100755 --- a/libexec/app-operate +++ b/libexec/app-operate @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/libexec/app-operator-pid b/libexec/app-operator-pid index 71871de..a3781ee 100755 --- a/libexec/app-operator-pid +++ b/libexec/app-operator-pid @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END @@ -80,8 +80,6 @@ find_pid_management() { command_start() { launcher=`find_launcher` - set -x - echo pwd=`pwd` pid_management=`find_pid_management` debug "launcher=$launcher" @@ -95,9 +93,10 @@ command_start() { ;; esac + export APPSH_HOME echo "Starting app..." $launcher <&- 1>&- 2>&- & - + PID=$! case "$pid_management" in @@ -205,7 +204,7 @@ then fatal "\$APP_HOME has to be set." fi -pid_file=$APP_HOME/.app/pid +pid_file=$APP_HOME/.app/pid PID= if [ -r $pid_file ] diff --git a/libexec/app-resolver-file b/libexec/app-resolver-file index 5aedf88..2b708e8 100755 --- a/libexec/app-resolver-file +++ b/libexec/app-resolver-file @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END @@ -31,7 +31,12 @@ init() { local file=${1-} - if [[ ! -r "$file" ]] + if [[ ! $file =~ ^/ ]] + then + fatal "The file's path must be absolute." + fi + + if [[ ! -r $file ]] then fatal "Can't read file: $file" fi diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index 25f7242..419adcc 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/libexec/app-run-hook b/libexec/app-run-hook index 9322fe4..a68ff84 100755 --- a/libexec/app-run-hook +++ b/libexec/app-run-hook @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/libexec/app-set-version b/libexec/app-set-version index 1b7fd16..f8ba31f 100755 --- a/libexec/app-set-version +++ b/libexec/app-set-version @@ -3,7 +3,7 @@ set -e set -u -APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) +export APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) . $APPSH_HOME/lib/common # HEADER END diff --git a/test/X-app-help.bats b/test/X-app-help.bats deleted file mode 100755 index 4b94f23..0000000 --- a/test/X-app-help.bats +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance" { - app instance; echo_lines - [ $status -eq $exit_usage_wrong ] - [ $(expr "${lines[0]}" : "usage: ./app instance .*") -ne 0 ] - [ ${#lines[*]} == 6 ] -} - -@test "./app instance install" { - app instance install; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: install .*") -ne 0 ] - [ ${#lines[*]} == 6 ] -} - -@test "./app instance list" { - app instance list; echo_lines - [ $status -eq 0 ] - [ ${#lines[*]} == 0 ] -} - -@test "./app instance list-versions" { - app instance list-versions; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: list-versions .*") -ne 0 ] - [ ${#lines[*]} == 1 ] -} - -@test "./app instance set-current" { - app instance "set-current"; echo_lines - [ $status -eq $exit_usage ] - [ $(expr "${lines[0]}" : "usage: set-current .*") -ne 0 ] - [ ${#lines[*]} == 1 ] -} diff --git a/test/X-app-install.bats b/test/X-app-install.bats deleted file mode 100755 index 18a84bc..0000000 --- a/test/X-app-install.bats +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -# TODO: Add test for installing duplicate version - -@test "./app install app-a" { - mkzip "app-a" - app install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/app-a.zip - - echo_lines - [ $status -eq 0 ] - [ "$output" = "Creating instance 'prod' for 'app-a' -Unpacking... -Changing current symlink -Running postinstall... -Hello World! -Creating logs directory -Postinstall completed successfully" ] - [ ${#lines[*]} == 7 ] -} - -@test "./app instance install install-test-env" { - mkzip "install-test-env" - app instance install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/install-test-env.zip \ - -v 1.0 - echo_lines - [ $status -eq 0 ] - [ "$output" = "Creating instance 'prod' for 'install-test-env' -Unpacking... -Changing current symlink -Running postinstall... -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=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0/root -SHLVL=1 -_=/usr/bin/env -Postinstall completed successfully" ] - [ ${#lines[*]} == 14 ] -# PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0 -} diff --git a/test/X-app-list-versions.bats b/test/X-app-list-versions.bats deleted file mode 100755 index de543eb..0000000 --- a/test/X-app-list-versions.bats +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance list-versions" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list-versions -n app-a -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Available versions for app-a/env-a: -1.0 -1.1" ] - - expected="1.0 -1.1" - -set -x - app -n app-a instance -i env-a list-versions -P; [ "$output" = "$expected" ]; echo_lines; - app -n app-a instance list-versions -i env-a -P; [ "$output" = "$expected" ]; echo_lines; - app instance list-versions -n app-a -i env-a -P; [ "$output" = "$expected" ]; echo_lines; -} diff --git a/test/X-app-list.bats b/test/X-app-list.bats deleted file mode 100755 index 3092837..0000000 --- a/test/X-app-list.bats +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app instance list - all apps" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-a env-b 1.0 -app-b env-a 1.0 -app-b env-b 1.0 " ] - - app instance list -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-a:env-b:1.0 -app-b:env-a:1.0 -app-b:env-b:1.0" ] -} - -@test "./app instance list - -n filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -n foo; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -n app-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-a env-b 1.0 " ] - - app instance list -n app-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-a:env-b:1.0" ] -} - -@test "./app instance list - -i filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -i foo; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 -app-b env-a 1.0 " ] - - app instance list -i env-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1 -app-b:env-a:1.0" ] -} - -@test "./app instance list - -n + -i filter" { - mkzip "app-a" - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 && - app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 - [ $status -eq 0 ] - - app instance list -n foo -i bar; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version " ] - - app instance list -n app-a -i env-a; echo_lines - [ $status -eq 0 ] - [ "$output" = "Name Instance Version -app-a env-a 1.1 " ] - - app instance list -n app-a -i env-a -P name -P instance -P version; echo_lines - [ $status -eq 0 ] - [ "$output" = "app-a:env-a:1.1" ] -} diff --git a/test/X-help.bats b/test/X-help.bats deleted file mode 100755 index eba4eeb..0000000 --- a/test/X-help.bats +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "./app" { - app; echo_lines - [ $status -eq $exit_usage_wrong ] - [ $(expr "${lines[0]}" : "usage: ./app .*") -ne 0 ] -} - -@test "./app foo" { - app foo; echo_lines - [ $status -eq $exit_usage_wrong ] - [ "${lines[0]}" = "Error: No such method group: foo" ] - [ $(expr "${lines[1]}" : "usage: ./app .*") -ne 0 ] -} diff --git a/test/app-upgrade.bats b/test/app-upgrade.bats index 4eef351..d27c6e7 100755 --- a/test/app-upgrade.bats +++ b/test/app-upgrade.bats @@ -13,17 +13,17 @@ load utils app conf get app.version eq '${lines[0]}' "1.0-SNAPSHOT" - app_version="${lines[0]}" + app_version="${lines[0]}" describe app_version = $app_version app conf get app.resolved_version match '${lines[0]}' "1.0-.*" - resolved_version="${lines[0]}" + resolved_version="${lines[0]}" describe resolved_version = $resolved_version app conf get app.installed_version match '${lines[0]}' "1.0-.*" - installed_version="${lines[0]}" + installed_version="${lines[0]}" describe installed_version = $installed_version eq '$installed_version' "$resolved_version" @@ -34,7 +34,7 @@ load utils app conf get app.resolved_version match '${lines[0]}' "1.0-.*" - new_resolved_version="${lines[0]}" + new_resolved_version="${lines[0]}" describe new_resolved_version = $new_resolved_version neq $new_resolved_version $resolved_version } -- cgit v1.2.3