#!/usr/bin/env bash
#
# Copyright (C) 2004 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

: <<-POD

=head1 NAME

ultrapossum-server - ultrapossum server daemon

=head1 SYNOPSYS

B<ultrapossum-server> [-v] <start|stop>

=head1 DESCRIPTION

B<ultrapossum-server> start or stop UltraPossum server. With -v option,
you can see the detail output.

=head1 AUTHOR

Masato Taruishi <taru@valinux.co.jp>

=cut

POD

prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
pkgdatadir=${prefix}/share/ultrapossum

PATH=$bindir:$sbindir:$PATH
export PATH

usage() {
  echo "Usage: $0 [-v] <start|stop>"
}

arg() {
  case "x$1" in
    xstart|xstop)
      return 0
    ;;
    x*)
      usage
      exit 1
    ;;
  esac
}

case "x$1" in
  x-h)
    usage
    exit 0
  ;;
  x-v)
    shift
    arg "$@"
    exec $pkgdatadir/module.d/server/startup "$@"
  ;;
  x*)
    arg "$@"
    if ! $pkgdatadir/module.d/server/startup "$@" 2> /dev/null > /dev/null
    then
      echo "E: failed to start ultrapossum-server. use -v to see the detail." 1>&2
    fi
  ;;
esac

