summaryrefslogtreecommitdiff
path: root/.app/lib/app-operate
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-14 11:26:54 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-14 11:26:54 +0200
commit2c7a659b8a8d0d7a082aed01ab44e5710841412b (patch)
treeb80f9d0db51282dc587211599a5bcc81dbfa6e09 /.app/lib/app-operate
parentcd470d4d622640a6b1a4d84082e3107ca44a16a4 (diff)
downloadapp.sh-2c7a659b8a8d0d7a082aed01ab44e5710841412b.tar.gz
app.sh-2c7a659b8a8d0d7a082aed01ab44e5710841412b.tar.bz2
app.sh-2c7a659b8a8d0d7a082aed01ab44e5710841412b.tar.xz
app.sh-2c7a659b8a8d0d7a082aed01ab44e5710841412b.zip
o Adjusting app-conf and app-operate after refactoring.
Diffstat (limited to '.app/lib/app-operate')
-rw-r--r--.app/lib/app-operate72
1 files changed, 24 insertions, 48 deletions
diff --git a/.app/lib/app-operate b/.app/lib/app-operate
index fc0d63f..d2f3a00 100644
--- a/.app/lib/app-operate
+++ b/.app/lib/app-operate
@@ -1,58 +1,24 @@
#!/bin/bash
-start_usage() {
+operate_usage() {
if [ -n "$1" ]
then
echo "Error:" "$@" >&2
fi
- echo "usage: $0 start -n name -i instance" >&2
- exit 1
-}
-
-stop_usage() {
- if [ -n "$1" ]
- then
- echo "Error:" "$@" >&2
- fi
-
- echo "usage: $0 stop -n name -i instance" >&2
+ echo "usage: $0 [operate method] -n name -i instance" >&2
exit 1
}
# TODO: set ulimit
# TODO: set umask
# TODO: change group newgrp/sg
-method_start() {
- run_control start_usage "start" "$@"
-}
-
-method_stop() {
- run_control stop_usage "stop" "$@"
-}
-
run_control() {
- local usage=$0; shift
local method=$1; shift
- local name
- local instance
-
- while getopts "n:i:" opt
- do
- case $opt in
- n)
- name=$OPTARG
- ;;
- i)
- instance=$OPTARG
- ;;
- \?)
- $usage "Invalid option: -$OPTARG"
- ;;
- esac
- done
+ local name=$1; shift
+ local instance=$1; shift
- assert_is_instance $usage "$name" "$instance"
+ assert_is_instance operate_usage "$name" "$instance"
(
cd $name/$instance/current
@@ -91,7 +57,7 @@ run_control() {
echo "Application ${method}ed"
;;
*)
- echo "Error starting $name/$instance"
+ echo "Error ${method}ing $name/$instance"
;;
esac
)
@@ -103,9 +69,9 @@ method_operate_usage() {
echo "Error:" $@ >&2
fi
- echo "usage: $0 operate <method>" >&2
+ echo "usage: $0 operate <operate method>" >&2
echo "" >&2
- echo "Available methods:" >&2
+ echo "Available operate methods:" >&2
echo " start" >&2
echo " stop" >&2
echo " restart" >&2
@@ -113,18 +79,28 @@ method_operate_usage() {
}
method_operate() {
+ local name="$1"; shift
+ local instance="$1"; shift
+ local method="$1"
+
if [ $# -gt 0 ]
then
- method=$1
shift
fi
case "$method" in
- start) method_start $first "$@" ;;
- stop) method_stop $first "$@" ;;
- status) method_status $first "$@" ;;
- restart) method_restart $first "$@" ;;
- *) method_operate_usage ;;
+ start) run_control "start" "$name" "$instance" "$@" ;;
+ stop) run_control "stop" "$name" "$instance" "$@" ;;
+ status) run_control "status" "$name" "$instance" "$@" ;;
+ restart) run_control "restart" "$name" "$instance" "$@" ;;
+ *)
+ if [ -z "$method" ]
+ then
+ method_operate_usage
+ else
+ method_operate_usage "Unknown method $method"
+ fi
+ ;;
esac
exit $?
}