LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File openstack-neutron.init of Package openstack-neutron (Project home:abel:branches:Cloud:OpenStack:Mitaka:Staging)

#! /bin/sh
### BEGIN INIT INFO
# Provides:          neutron-server
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      mysql postgresql rabbitmq-server openstack-keystone
# Should-Stop:       mysql postgresql rabbitmq-server openstack-keystone
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: neutron-server
# Description:       Provides the Neutron networking service
### END INIT INFO

NEUTRON_LOGFILE="/var/log/neutron/neutron-server.log"
NEUTRON_SYSCONFIG=/etc/sysconfig/neutron
NEUTRON_CONF=/etc/neutron/neutron.conf
test -r $NEUTRON_SYSCONFIG || exit 6
. $NEUTRON_SYSCONFIG

CONF_ARGS="--config-file /etc/neutron/neutron.conf"
for i in $NEUTRON_PLUGIN_CONF; do
        CONF_ARGS="$CONF_ARGS --config-file $i"
done
USER="neutron"
DAEMON=/usr/bin/neutron-server
DAEMON_ARGS="--log-file $NEUTRON_LOGFILE $CONF_ARGS"
DAEMON_DIR=/var/run

export TMPDIR=/var/lib/neutron/tmp

if [ ! -x ${DAEMON} ] ; then
	exit 0
fi

. /etc/rc.status

neutron_server_running () {
    # Check the response code of the "List API versions" call.
    # If it's 200, we consider neutron-server is properly running.
    http_code=$(
        curl \
            --silent --write-out %{http_code} --output /dev/null \
            -X GET http://${bind_host}:${bind_port}
    )
    rc=$?
    if [ $rc -ne 0 ] || [ $http_code -ne 200 ]; then
        return 1
    fi
    return 0
}

wait_for_neutron_api () {
    if ! bind_host=`crudini --get $NEUTRON_CONF DEFAULT bind_host`; then
        # Defaults to 0.0.0.0, so we can use localhost
        bind_host=localhost
    fi

    if ! bind_port=`crudini --get $NEUTRON_CONF DEFAULT bind_port`; then
        bind_port=9696
    fi

    until neutron_server_running; do
        sleep 2
    done
}

case "$1" in
  start)
    echo -n "Checking for DB Migrations"
    su $USER -s /bin/sh -c "/usr/bin/neutron-db-manage $CONF_ARGS upgrade head"
    rc_status -v

    echo -n "Starting neutron server"
    startproc -t ${STARTUP_TIMEOUT:-5} -q -s -u $USER $DAEMON $DAEMON_ARGS
    ret=$?
    if [ $ret = 0 ]; then
        # Ensure start-up is synchronous, i.e. blocking until neutron
        # really is ready, otherwise services which depend on it (e.g.
        # neutron-ha-tool) could fail unexpectedly.
        # https://bugzilla.suse.com/show_bug.cgi?id=965886
        wait_for_neutron_api
        ret=$?
    fi
    ( exit $ret ) # pass the right exit code to rc_status
    rc_status -v
    ;;
  stop)
    echo -n "Stopping neutron server"
    killproc $DAEMON
    rc_status -v
    ;;
  restart|force-reload)
    $0 stop
    sleep 1
    $0 start
    ;;
  reload)
    ;;
  status)
    echo -n "Checking status of neutron server"
    /sbin/checkproc $DAEMON
    rc_status -v
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|force-reload|status}"
    exit 2
    ;;
esac

exit $?