aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-09 18:49:27 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-09 18:59:21 +0200
commit8b1d11508e985cc2cd97a1d70d01574e78109569 (patch)
tree0f16b0320c8417e27150f305a6b316c3438c23b9 /app
parentcb38e87306cde54144867ef7141682fc7fad0980 (diff)
downloadapp.sh-8b1d11508e985cc2cd97a1d70d01574e78109569.tar.gz
app.sh-8b1d11508e985cc2cd97a1d70d01574e78109569.tar.bz2
app.sh-8b1d11508e985cc2cd97a1d70d01574e78109569.tar.xz
app.sh-8b1d11508e985cc2cd97a1d70d01574e78109569.zip
o Reworked app starting.
Diffstat (limited to 'app')
-rwxr-xr-xapp102
1 files changed, 48 insertions, 54 deletions
diff --git a/app b/app
index e52e61d..5fd0d11 100755
--- a/app
+++ b/app
@@ -261,10 +261,33 @@ start_usage() {
exit 1
}
+stop_usage() {
+ if [ -n "$1" ]
+ then
+ echo "Error:" $@ >&2
+ fi
+
+ echo "usage: $0 stop -n name -i instance" >&2
+ exit 1
+}
+
# TODO: set ulimit
# TODO: set umask
# TODO: change group newgrp/sg
method_start() {
+ run_method start_usage "start" "$@"
+}
+
+method_stop() {
+ run_method stop_usage "stop" "$@"
+}
+
+run_method() {
+ local usage=$0; shift
+ local method=$1; shift
+ local name
+ local instance
+
while getopts "n:i:" opt
do
case $opt in
@@ -275,82 +298,53 @@ method_start() {
instance=$OPTARG
;;
\?)
- start_usage "Invalid option: -$OPTARG"
+ $usage "Invalid option: -$OPTARG"
;;
esac
done
- assert_is_instance start_usage "$name" "$instance"
+ assert_is_instance $usage "$name" "$instance"
(
cd $name/$instance/current
- bin=`get_conf app.start`
+ bin=`get_conf $BASEDIR $name $instance app.method`
if [ -z "$bin" ]
then
- bin=`find bin -type f`
+ bin=$BASEDIR/.app/lib/default-method
+ fi
- if [ ! -x "$bin" ]
- then
- echo "No app.start configured, couldn't detect an executable file to execute." >&2
- exit 1
- fi
- elif [ ! -x "$bin" ]
+ if [ ! -x "$bin" ]
then
echo "Invalid executable: $bin" >&2
exit 1
fi
- e=`get_conf_in_group env`
+ e=`get_conf_in_group $BASEDIR $name $instance env`
- env -i $e \
- $bin &
+ set +e
set -x
- PID=$!
- echo $PID > $BASEDIR/.app/var/pid/$name-$instance.pid
- )
-}
-
-method_stop() {
- while getopts "n:i:" opt
- do
- case $opt in
- n)
- name=$OPTARG
- ;;
- i)
- instance=$OPTARG
+ env -i \
+ $e \
+ PATH=/bin:/usr/bin \
+ APPSH_METHOD=$method \
+ APPSH_BASEDIR=$BASEDIR \
+ APPSH_NAME=$name \
+ APPSH_INSTANCE=$instance \
+ $bin
+ local ret=$?
+ set +x
+ set -e
+
+ case $ret in
+ 0)
+ echo "Application ${method}ed"
;;
- \?)
- start_usage "Invalid option: -$OPTARG"
+ *)
+ echo "Error starting $name/$instance"
;;
esac
- done
-
- assert_is_instance stop_usage "$name" "$instance"
-
- (
- cd $name/$instance/current
-
- bin=`get_conf app.stop`
-
- if [ -z "$bin" ]
- then
- PID=`cat $BASEDIR/.app/var/pid/$name-$instance.pid`
- echo "Sending TERM to $PID"
- bin="kill $PID"
- elif [ ! -x "$bin" ]
- then
- echo "Invalid executable: $bin" >&2
- exit 1
- fi
-
- e=`get_conf_in_group env`
-
- env -i $e \
- PID=$PID \
- $bin &
)
}