#!/bin/bash

#--
# Copyright 2012 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++

# Idle applications
#
# oo-idler takes an existing running application and disables it to free up
# memory and cpu resources.  It uses oo-restorer to automatically turn the
# application back on when a request comes to it (like
# http://app-dom.example.com)

function print_help {
    echo "Usage: $0"
    echo "  -u UUID       idles the app"
    echo "  -l            list all idled apps"
    exit 1
}

while getopts 'u:dln' OPTION
do
    case $OPTION in
        u)
            $(dirname -- "$0")/oo-admin-ctl-gears idlegear $OPTARG
            /usr/bin/logger -p local0.notice -t oo_idler "Idled: $OPTARG"
            ;;
        d) # deprecated option
            ;;
        l)
            $(dirname -- "$0")/oo-admin-ctl-gears listidle
            ;;
        n) # deprecated option
            ;;
        ?) print_help
            ;;
    esac
done
