summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-07 18:38:10 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-07 18:38:10 +0200
commit038106cc4bca5e5a7273679bf090f8cca544679c (patch)
treee59480c112e69af91254f6c08bdc21ba55e4ea70 /app
parent59ca77dc22f9356b8f5c400c94a04b1bda899ea6 (diff)
downloadapp.sh-038106cc4bca5e5a7273679bf090f8cca544679c.tar.gz
app.sh-038106cc4bca5e5a7273679bf090f8cca544679c.tar.bz2
app.sh-038106cc4bca5e5a7273679bf090f8cca544679c.tar.xz
app.sh-038106cc4bca5e5a7273679bf090f8cca544679c.zip
o Renaming latest to current.
o Adding stop method. o Saving pids under .apps/var/pid.
Diffstat (limited to 'app')
-rwxr-xr-xapp73
1 files changed, 60 insertions, 13 deletions
diff --git a/app b/app
index 30254d5..bb46441 100755
--- a/app
+++ b/app
@@ -6,7 +6,8 @@ BASEDIR=`dirname $0`
BASEDIR=`cd $BASEDIR; pwd`
export BASEDIR
-mkdir -p $BASEDIR/.app/var
+mkdir -p $BASEDIR/.app/var/pid
+mkdir -p $BASEDIR/.app/var/download
if [ -n "$APPSH_REPO" ]
then
@@ -39,8 +40,7 @@ resolve_snapshot() {
local metadata
echo "Resolving version $version..."
- mkdir -p downloads
- metadata=downloads/$groupId-$artifactId-$version-metadata.xml
+ metadata=$BASEDIR/.app/var/download/$groupId-$artifactId-$version-metadata.xml
base_url=$repo/$(echo $groupId | sed "s,\.,/,g")/$artifactId/$version
get $base_url/maven-metadata.xml $metadata
resolved_version=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $metadata`
@@ -55,7 +55,7 @@ resolve_snapshot() {
zip_file=
download_artifact() {
- zip_file=downloads/$groupId-$artifactId-$resolved_version.zip
+ zip_file=$BASEDIR/.app/var/download/$groupId-$artifactId-$resolved_version.zip
if [ -r $zip_file ]
then
echo "Artifact already downloaded."
@@ -89,9 +89,9 @@ assert_is_instance() {
exit 1
fi
- if [ ! -e $name/$instance/latest ]
+ if [ ! -e $name/$instance/current ]
then
- echo "Missing 'latest' link." >&2
+ echo "Missing 'current' link." >&2
exit 1
fi
@@ -228,12 +228,12 @@ method_install() {
fi
)
- echo "Changing latest symlink"
- rm -f $name/$instance/latest
- ln -s versions/$resolved_version/root $name/$instance/latest
+ echo "Changing current symlink"
+ rm -f $name/$instance/current
+ ln -s versions/$resolved_version/root $name/$instance/current
(
- cd $name/$instance/latest
+ cd $name/$instance/current
find bin -type f | xargs chmod +x
)
@@ -277,7 +277,7 @@ method_start() {
assert_is_instance start_usage "$name" "$instance"
(
- cd $name/$instance/latest
+ cd $name/$instance/current
bin=`get_conf app.start`
@@ -300,11 +300,55 @@ method_start() {
env -i $e \
$bin &
- PID=`echo $!`
- echo $PID > $BASEDIR/.app/var/$name-$instance.pid
+ 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
+ ;;
+ \?)
+ start_usage "Invalid option: -$OPTARG"
+ ;;
+ 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 &
+ )
+}
+
+
method_list() {
printf "%20s %20s %20s\n" "instance" "name" "version"
@@ -344,6 +388,9 @@ case "$method" in
start)
method_start $@
;;
+ stop)
+ method_stop $@
+ ;;
list)
method_list $@
;;