#!/bin/sh
#
# $FreeBSD: ports/security/dradis/files/dradis.in,v 1.2 2011/01/09 22:06:07 ohauer Exp $
#
# PROVIDE: dradis
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable dradis:
# dradis_enable="YES"
#
# Additional settings:
# dradis_bindip="127.0.0.1"     # IP: default 120.0.0.1
# dradis_port="3004"            # listen port: default 3004
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#

. /etc/rc.subr

name=dradis
rcvar=`set_rcvar`

dradis_enable=${dradis_enable-"NO"}
dradis_bindip=${dradis_bindip-"127.0.0.1"}
dradis_port=${dradis_port-"3004"}

command=/usr/local/bin/ruby
start_cmd=dradis_start
sig_stop=INT
extra_commands="initdb"
initdb_cmd="dradis_initdb"

dradis_initdb()
{
    cd /usr/local/dradis/server &&
    env RAILS_ENV=production /usr/local/bin/rake dradis:reset
}

dradis_start()
{
    cd /usr/local/dradis/server  &&
    env RAILS_ENV=production /usr/local/bin/ruby script/rails server -d -b ${dradis_bindip} -p ${dradis_port}
}

load_rc_config $name
run_rc_command "$1"
