#!/bin/sh -e
#
# gandi-postboot     Start/Stop the Gandi setup script from customer.
#
# chkconfig: 2345 52 25
# description: initscript which run customer configuration script \
#              in Gandi IaaS hosting virtual machine
# processname: gandi-postboot
# config: /etc/sysconfig/gandi
# pidfile: /var/run/gandi-postboot.pid
#
### BEGIN INIT INFO
# Provides: gandi-postboot
# Required-Start: $all $remote_fs
# Required-Stop: 
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Start-Before:
# Short-Description: gandi-postboot run customer configuration script.
# Description: initscript which run customer configuration script \
#              in Gandi IaaS hosting virtual machine
### END INIT INFO

# author : Nicolas Chipaux <aegiap@gandi.net> for Gandi.net
# all rights reserved.

# Cutomer of the IaaS hosting can provide a script which will be executed as 
# root on the virtual machine and find some configuration in a JSON form in
# /gandi/config

case "$1" in
    start|restart|reload)
	if [ -x /gandi/init ]; then
            pbin=/usr/bin/python2
            [ -x $pbin ] || pbin=/usr/bin/python
            $pbin /gandi/init --postboot
            rm -f /gandi/init
        fi
    ;;
    stop|force-reload|status)
	# nothing
    ;;
    *)
	echo "Script only started at boot for system configuration."
    ;;
esac

exit 0
