From 83c13f1181c4062ca5296ea956e950064bde0ffe Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 18 Oct 2012 13:38:58 +0200 Subject: o Making all scripts be run from the root/ directory. Do not assume you're in current/. --- .app/lib/app-instance | 5 +++-- .app/lib/app-operate | 9 +-------- .app/lib/pid-method | 14 ++++++++------ docs/README.md | 12 +++++++----- test/app-install.bats | 6 ++++-- test/data/app-a/root/bin/app-a | 11 ++++++----- test/data/app-a/scripts/postinstall | 18 ++++++++++++++---- test/it-install-remove.bats | 11 ++++------- 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.app/lib/app-instance b/.app/lib/app-instance index 89102b5..5b34bf1 100644 --- a/.app/lib/app-instance +++ b/.app/lib/app-instance @@ -191,7 +191,7 @@ method_install() { echo "Unpacking..." unzip -q -d $name/$instance/versions/$resolved_version $zip_file - if [ ! -d $apps/$name/$instance/versions/$resolved_version/root ] + if [ ! -d $name/$instance/versions/$resolved_version/root ] then echo "Invalid zip file, did not contain a ./root directory." >&2 exit 1 @@ -207,6 +207,7 @@ method_install() { if [ -x scripts/postinstall ] then echo "Running postinstall..." + cd root set +e env -i \ PATH=/bin:/usr/bin \ @@ -215,7 +216,7 @@ method_install() { APPSH_NAME=$name \ APPSH_INSTANCE=$instance \ APPSH_VERSION=$resolved_version \ - scripts/postinstall + ../scripts/postinstall set -e ret=`echo $?` if [ "$ret" != 0 ] diff --git a/.app/lib/app-operate b/.app/lib/app-operate index 45e3da2..83ca100 100644 --- a/.app/lib/app-operate +++ b/.app/lib/app-operate @@ -45,6 +45,7 @@ run_control() { env -i \ PATH=/bin:/usr/bin \ $e \ + PWD=$PWD \ APPSH_METHOD=$method \ APPSH_APPS=$apps \ APPSH_HOME=$APPSH_HOME \ @@ -56,14 +57,6 @@ run_control() { set +x set -e -# case $ret in -# 0) -# echo "Method ${method} completed successfully for $name/$instance" -# ;; -# *) -# echo "Error running method ${method} for $name/$instance" -# ;; -# esac exit $ret ) } diff --git a/.app/lib/pid-method b/.app/lib/pid-method index 55d74b8..29f6b4f 100755 --- a/.app/lib/pid-method +++ b/.app/lib/pid-method @@ -2,12 +2,13 @@ set -u -PID_FILE=$APPSH_APPS/.app/var/pid/$APPSH_NAME-$APPSH_INSTANCE.pid - . $APPSH_HOME/.app/lib/app-conf +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 @@ -23,9 +24,9 @@ fi chmod +x "$bin" PID= -if [ -r $PID_FILE ] +if [ -r $pid_file ] then - PID="`cat $PID_FILE`" + PID="`cat $pid_file`" fi do_status() { @@ -51,9 +52,10 @@ method_start() { esac $bin <&- 1<&- 2<&- & + PID=$! echo "Application launched as $PID" - echo $PID > $PID_FILE + echo $PID > $pid_file return 0 } @@ -83,7 +85,7 @@ method_stop() { done echo " OK" - rm -f $PID_FILE + rm -f $pid_file return 0 } diff --git a/docs/README.md b/docs/README.md index 4649ce3..9ae11fa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -41,6 +41,9 @@ TODOs * Rename "scripts/" to handlers or something similar. Perhaps just remove it entirely. +* Document how the operate method (custom pid-method stuff) can see + its own output for debugging. + Commands -------- @@ -104,7 +107,7 @@ Method Contract Unclassified: * `APPSH_HOME` -* `BASEDIR` +* `APPSH_APPS` Directory Hierarchy ------------------- @@ -113,7 +116,7 @@ Directory Hierarchy 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 +contains the app.sh libraries is known as `$APPSH_HOME`. App.sh related: @@ -125,11 +128,10 @@ App.sh related: Applications: ./// - Known as $APPSH_INSTANCE_HOME - current - symlink to the currently installed app + 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/ + root/ - The current directory when executing methods and scripts scripts/ 1.1/ 2.0/ diff --git a/test/app-install.bats b/test/app-install.bats index df77594..7c7d642 100755 --- a/test/app-install.bats +++ b/test/app-install.bats @@ -18,9 +18,10 @@ load utils Unpacking... Running postinstall... Hello World! +Creating logs directory Postinstall completed successfully Changing current symlink" ] - [ ${#lines[*]} == 6 ] + [ ${#lines[*]} == 7 ] } @test "./app instance install install-test-env" { @@ -40,10 +41,11 @@ 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 +PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0/root SHLVL=1 _=/usr/bin/env Postinstall completed successfully Changing current symlink" ] [ ${#lines[*]} == 14 ] +# PWD=$APPSH_APPS_CANONICAL/install-test-env/prod/versions/1.0 } diff --git a/test/data/app-a/root/bin/app-a b/test/data/app-a/root/bin/app-a index c8c4fc5..98d98cd 100644 --- a/test/data/app-a/root/bin/app-a +++ b/test/data/app-a/root/bin/app-a @@ -1,15 +1,16 @@ #!/bin/bash -me=$APPSH_INSTANCE_HOME/`basename $0` +#cd $APPSH_INSTANCE_HOME +me=`basename $0` -echo "Starting" >> $me.log +env | grep TEST_PROPERTY >> logs/$me.env -env | grep TEST_PROPERTY > $me.env +echo "Starting" >> logs/$me.log for i in {1..10} do - echo "#$i: `date`" >> $me.log + echo "#$i: `date`" >> logs/$me.log sleep 1 done -echo "Exiting" >> $me.log +echo "Exiting" >> logs/$me.log diff --git a/test/data/app-a/scripts/postinstall b/test/data/app-a/scripts/postinstall index a77f86f..c1a0cf1 100644 --- a/test/data/app-a/scripts/postinstall +++ b/test/data/app-a/scripts/postinstall @@ -1,11 +1,21 @@ -#!/bin/bash +#!/bin/bash -e echo "Hello World!" -if [ -d root/etc/$APPSH_INSTANCE ] +if [ -d etc/$APPSH_INSTANCE ] then - find root/etc/$APPSH_INSTANCE -type f -maxdepth 1 | while read file + find etc/$APPSH_INSTANCE -type f -maxdepth 1 | while read file do - cp $file root/ + cp $file . done fi + +LOGS=$APPSH_APPS/$APPSH_NAME/$APPSH_INSTANCE/logs + +if [ ! -d $LOGS ] +then + echo "Creating logs directory" + mkdir $LOGS +fi + +ln -s $LOGS logs diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats index 5eb9f46..78f4532 100755 --- a/test/it-install-remove.bats +++ b/test/it-install-remove.bats @@ -34,15 +34,12 @@ load utils echo_lines can_not_read .app/var/pid/$name-$instance.pid - can_read "$name/$instance/$name.log" - can_read "$name/$instance/$name.env" + can_read "$name/$instance/logs/$name.log" + can_read "$name/$instance/logs/$name.env" can_read "$name/$instance/current/foo.conf" - [ "`cat $name/$instance/$name.env`" = "TEST_PROPERTY=awesome" ] + [ "`cat $name/$instance/logs/$name.env`" = "TEST_PROPERTY=awesome" ] [ "`cat $name/$instance/current/foo.conf`" = "hello" ] -# app instance install \ -# -r file \ -# -u $HOME/.m2/repository/io/trygvis/appsh/examples/jenkins/1.0-SNAPSHOT/jenkins-1.0-SNAPSHOT.zip \ -# -n jenkins -i env-a + # TODO: Remove the version } -- cgit v1.2.3