#!/bin/sh
#
# $FreeBSD: net/openvswitch/files/ovsdb-server.in 302330 2012-08-09 08:22:10Z trasz $
#

# PROVIDE: ovsdb_server
# REQUIRE: LOGIN

. /etc/rc.subr

name="ovsdb_server"
rcvar=ovsdb_server_enable

command="/usr/local/sbin/ovsdb-server"
pidfile="/usr/local/var/run/ovsdb-server.pid"
start_precmd="ovsdb_server_precmd"

load_rc_config $name

: ${ovsdb_server_enable="NO"}
: ${ovsdb_server_sock="/usr/local/var/run/openvswitch/db.sock"}
: ${ovsdb_server_database="/usr/local/etc/openvswitch/conf.db"}

ovsdb_server_precmd() {
	[ -e "`dirname $ovsdb_server_database`" ] || \
		mkdir -p "`dirname $ovsdb_server_database`"
	[ -e "$ovsdb_server_database" ] || \
		/usr/local/bin/ovsdb-tool create "$ovsdb_server_database" \
		/usr/local/share/openvswitch/vswitch.ovsschema
}

command_args="--detach --pidfile=$pidfile \
	--remote=punix:$ovsdb_server_sock \
	--remote=db:Open_vSwitch,manager_options \
	--private-key=db:SSL,private_key \
	--certificate=db:SSL,certificate \
	--bootstrap-ca-cert=db:SSL,ca_cert \
	$ovsdb_server_database"

run_rc_command "$1"
