aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--.app/lib/app-conf12
-rw-r--r--.app/lib/app-operate72
2 files changed, 27 insertions, 57 deletions
diff --git a/.app/lib/app-conf b/.app/lib/app-conf
index fa705e4..29b74dd 100644
--- a/.app/lib/app-conf
+++ b/.app/lib/app-conf
@@ -111,19 +111,13 @@ method_conf_usage() {
}
method_conf() {
- local name
- local instance
+ local name="$1"; shift
+ local instance="$1"; shift
local mode="list"
- while getopts "n:i:s:d:" opt
+ while getopts "s:d:" opt
do
case $opt in
- n)
- name="$OPTARG"
- ;;
- i)
- instance="$OPTARG"
- ;;
d)
mode="delete"
key="$OPTARG"
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 $?
}