#! /bin/sh
# Copyright 2013 Google Inc. All Rights Reserved.
#
# 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.
#
### BEGIN INIT INFO
# Provides:    gce_onboot
# X-Start-Before:    ssh
# Required-Start:    $local_fs $network $syslog
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Google Compute Engine on-boot services
# Description:       This launches the Google Compute Engine
#        VM initialization scripts.
### END INIT INFO

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

# If we're running under upstart, let the upstart config file handle things.
# Debian 7 and newer have a near-one-liner function to detect this...
if type init_is_upstart >/dev/null 2>&1; then
  # ... which we can use if present.
  init_is_upstart && exit 0
else
  # Otherwise, directly include the core line of Debian 7's version.
  # Authorship credit: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=661109
  if [ -x /sbin/initctl ] && /sbin/initctl version | /bin/grep -q upstart; then
    exit 0
  fi
fi

DESC="Google Compute Engine on-boot services"
NAME="onboot"

#
# Function that starts the daemon/service
#
do_start()
{
  /usr/share/google/onboot
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
      0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
      *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  *)
    echo "Usage: $SCRIPTNAME start" >&2
    exit 3
    ;;
esac

:
