
#!/bin/sh
#
# PROVIDE: meshd
# REQUIRE: network
# REQUIRE: db
# KEYWORD: shutdown
#
# Documentation about system:
# http://wiki.yandex-team.ru/Robot/PageRank
#

. /etc/rc.subr

name="meshd"
rcvar=`set_rcvar`

load_rc_config $name

: ${meshd_enable="NO"}
: ${meshd_user="pagerank"}
: ${meshd_dir="/Berkanavt/mesh/meshd"}
: ${meshd_limits="-e -C worm"}
: ${meshd_port="35000"}

meshd_host=`hostname -f`
pidfile="${meshd_dir}/jobs/pid"
command="${meshd_dir}/bin/meshd"
command_args="-h ${meshd_host} -p ${meshd_port} -d ${meshd_dir}/jobs -l ${meshd_dir}/log/meshd.log -c ${meshd_dir}/meshd.cfg"

required_dirs="${meshd_dir}"

start_precmd="${name}_precmd"

extra_commands="check"
check_cmd="${name}_check"

meshd_check() {
    if [ -z `check_pidfile ${pidfile} ${command}` ]; then
        run_rc_command start
    fi
}

meshd_precmd()
{
    export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:${meshd_dir}/bin
    export USER=${meshd_user}
    export HOME=${meshd_dir}

    cd ${meshd_dir}

    if [ -n "${meshd_limits}" ]; then
        eval `/usr/bin/limits ${meshd_limits}` 2>/dev/null
    fi
}

run_rc_command "$1"
