From 5cf3abf29e3451ce2a86cfa400e36cbb53552354 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 10 Jan 2013 13:34:04 +0100 Subject: o Making run_control more generic and renamed to run_app. --- .app/lib/app-common | 56 ++++++++++++++++++++++++++++++++++++++-- .app/lib/app-operate | 73 +++++++++++++--------------------------------------- docs/README.md | 39 +++++++++++++++++++++++----- 3 files changed, 105 insertions(+), 63 deletions(-) diff --git a/.app/lib/app-common b/.app/lib/app-common index 0d33c84..3856430 100644 --- a/.app/lib/app-common +++ b/.app/lib/app-common @@ -16,7 +16,14 @@ assert_is_instance() { $usage "Missing required option -i." fi - if [ ! -d $name/$instance ] + # Use $APPSH_APPS as prefix if it's set + local x="" + if [ ! -z "$APPSH_APPS" ] + then + x="$APPSH_APPS/" + fi + + if [ ! -d $x$name/$instance ] then echo "No such instance: $name/$instance." >&2 exit 1 @@ -24,7 +31,7 @@ assert_is_instance() { if [ "$check_link" != "no" ] then - if [ ! -e $name/$instance/current ] + if [ ! -e $x$name/$instance/current ] then echo "Missing 'current' link." >&2 exit 1 @@ -103,3 +110,48 @@ find_versions() { ls -1d * ) } + +# TODO: set ulimit +# TODO: set umask +# TODO: change group newgrp/sg +run_app() { + local name=$1; shift + local instance=$1; shift + local bin=$1; shift + local method=$1; shift + + assert_is_instance operate_usage "$name" "$instance" + + local x="" + if [ ! -z "$APPSH_APPS" ] + then + x="$APPSH_APPS/" + fi + + ( + cd $x$name/$instance + APPSH_INSTANCE_HOME=`pwd` + cd current + + e="`get_conf_in_group $apps $name $instance env`" + + # Set a default PATH which can be overridden by the application's settings + set +e + env -i \ + PATH=/bin:/usr/bin \ + $e \ + PWD=$PWD \ + APPSH_METHOD=$method \ + APPSH_APPS=$apps \ + APPSH_HOME=$APPSH_HOME \ + APPSH_NAME=$name \ + APPSH_INSTANCE=$instance \ + APPSH_INSTANCE_HOME=$APPSH_INSTANCE_HOME \ + $bin "$@" + local ret=$? + set +x + set -e + + exit $ret + ) +} diff --git a/.app/lib/app-operate b/.app/lib/app-operate index f361173..2b1408d 100644 --- a/.app/lib/app-operate +++ b/.app/lib/app-operate @@ -10,57 +10,6 @@ operate_usage() { exit 1 } -# TODO: set ulimit -# TODO: set umask -# TODO: change group newgrp/sg -run_control() { - local method=$1; shift - local name=$1; shift - local instance=$1; shift - - assert_is_instance operate_usage "$name" "$instance" - - ( - cd $name/$instance - APPSH_INSTANCE_HOME=`pwd` - cd current - - bin=`get_conf $apps $name $instance app.method` - - if [ -z "$bin" ] - then - bin=$APPSH_HOME/.app/lib/pid-method - fi - - if [ ! -x "$bin" ] - then - echo "Invalid executable: $bin" >&2 - exit 1 - fi - - e="`get_conf_in_group $apps $name $instance env`" - - # Set a default PATH which can be overridden by the application's settings - set +e - env -i \ - PATH=/bin:/usr/bin \ - $e \ - PWD=$PWD \ - APPSH_METHOD=$method \ - APPSH_APPS=$apps \ - APPSH_HOME=$APPSH_HOME \ - APPSH_NAME=$name \ - APPSH_INSTANCE=$instance \ - APPSH_INSTANCE_HOME=$APPSH_INSTANCE_HOME \ - $bin "$@" - local ret=$? - set +x - set -e - - exit $ret - ) -} - method_operate_usage() { if [ -n "$1" ] then @@ -86,11 +35,25 @@ method_operate() { shift fi + bin=`get_conf $apps $name $instance app.method` + + if [ -z "$bin" ] + then + bin=$APPSH_HOME/.app/lib/pid-method + fi + + if [ ! -x "$name/$instance/current/$bin" ] + then + echo "Invalid executable: $bin" >&2 + exit 1 + fi + case "$method" in - start) run_control "start" "$name" "$instance" "$@" ;; - stop) run_control "stop" "$name" "$instance" "$@" ;; - status) run_control "status" "$name" "$instance" "$@" ;; - restart) run_control "restart" "$name" "$instance" "$@" ;; + start) run_app "$name" "$instance" "$bin" "start" "$@" ;; + stop) run_app "$name" "$instance" "$bin" "stop" "$@" ;; + status) run_app "$name" "$instance" "$bin" "status" "$@" ;; + restart) run_app "$name" "$instance" "$bin" "restart" "$@" ;; + run) run_app "$name" "$instance" "$bin" "run" "$@" ;; *) if [ -z "$method" ] then diff --git a/docs/README.md b/docs/README.md index d43f912..c4a83e9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,11 +13,6 @@ NOTE: The bash completion is not perfect yet. Or was it `~/.bash_profile`? hmm -Environment ------------ - -The following environment variables are set by default: - TODOs ----- @@ -34,7 +29,8 @@ TODOs * Concept: config. group, key and value. * Scriptable -* init.d support +* init.d support - register the application under /etc/init.d on + installation. Should probably be a plugin. * Support -h for all applicable methods to show the help/usage. @@ -137,3 +133,34 @@ Applications: scripts/ 1.1/ 2.0/ + +Creating Apps +------------- + +"App bundles" are basically just zip file with a specific layout. It +has to contain at least a `root/` directory which contains your +application. It can contain anything. The `current` symlink will point +to this directory. + +The bundle can also contain a special `scripts` directory which +contains scripts that's run durtion package operations. Only +`postinstall` is currently supported. + +Zip File Tree +============= + + root/ + bin/ + myapp + etc/ + config + scripts/ + postinstall + +Managing Apps +------------- + +Setting Environment Variables +----------------------------- + + app -n .. -i .. conf -- cgit v1.2.3