#!/bin/bash
#
# Copyright © 2012-2014 Cask Data, 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.
#
#
# chkconfig: 2345 96 15
# description: Starts and stops the coopr-ui service
# 
### BEGIN INIT INFO
# Provides:          coopr-ui
# Short-Description: Coopr UI
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Required-Start:    $network
# Required-Stop:     $network
# Should-Start:
# Should-Stop:
### END INIT INFO

# source /etc/default/coopr-ui
[ -f /etc/default/coopr-ui ] && source /etc/default/coopr-ui

# create pid dir owned by coopr user
mkdir -p /var/run/coopr
chown -R coopr:coopr /var/run/coopr

# drop permissions to coopr user and run service script

if [[ $UID -eq 0 ]]; then
    su coopr -c "cd /opt/coopr/ui/bin; exec ./ui.sh $*"
else
    cd /opt/coopr/ui/bin; exec ./ui.sh $*
fi

