#!@l_prefix@/bin/openpkg rc
##
##  rc.ethereum-bootnode -- Run-Commands
##

%config
    ethereum_bootnode_enable="$openpkg_rc_def"
    ethereum_bootnode_flags="-addr 127.0.0.1:30301 -verbosity 9"
    ethereum_bootnode_log_prolog="true"
    ethereum_bootnode_log_epilog="true"
    ethereum_bootnode_log_numfiles="10"
    ethereum_bootnode_log_minsize="1M"
    ethereum_bootnode_log_complevel="9"

%common
    ethereum_bootnode_cfgfile="@l_prefix@/etc/ethereum-bootnode/ethereum-bootnode.key"
    ethereum_bootnode_datdir="@l_prefix@/var/ethereum-bootnode/data"
    ethereum_bootnode_pidfile="@l_prefix@/var/ethereum-bootnode/run/ethereum-bootnode.pid"
    ethereum_bootnode_logfile="@l_prefix@/var/ethereum-bootnode/log/ethereum-bootnode.log"
    ethereum_bootnode_signal () {
        [ -f $ethereum_bootnode_pidfile ] && kill -$1 `cat $ethereum_bootnode_pidfile`
    }

%status -u @l_rusr@ -o
    ethereum_bootnode_usable="unknown"
    ethereum_bootnode_active="no"
    rcService ethereum-bootnode enable yes && \
        ethereum_bootnode_signal 0 && ethereum_bootnode_active="yes"
    echo "ethereum_bootnode_enable=\"$ethereum_bootnode_enable\""
    echo "ethereum_bootnode_usable=\"$ethereum_bootnode_usable\""
    echo "ethereum_bootnode_active=\"$ethereum_bootnode_active\""

%start -u @l_rusr@
    rcService ethereum-bootnode enable yes || exit 0
    rcService ethereum-bootnode active yes && exit 0
    (   GOMAXPROCS=32
        export GOMAXPROCS
        nohup @l_prefix@/bin/ethereum-bootnode \
            -nodekey "$ethereum_bootnode_cfgfile" \
            $ethereum_bootnode_flags \
        </dev/null >>$ethereum_bootnode_logfile 2>&1 &
        echo $! >$ethereum_bootnode_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService ethereum-bootnode enable yes || exit 0
    rcService ethereum-bootnode active no  && exit 0
    ethereum_bootnode_signal TERM
    sleep 2
    rm -f $ethereum_bootnode_pidfile >/dev/null 2>&1 || true

%restart -u @l_rusr@
    rcService ethereum-bootnode enable yes || exit 0
    rcService ethereum-bootnode active no  && exit 0
    rc ethereum-bootnode stop start

%daily -u @l_susr@
    rcService ethereum-bootnode enable yes || exit 0
    shtool rotate -f \
        -n ${ethereum_bootnode_log_numfiles} -s ${ethereum_bootnode_log_minsize} -d \
        -z ${ethereum_bootnode_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${ethereum_bootnode_log_prolog}" \
        -E "${ethereum_bootnode_log_epilog}; rc ethereum-bootnode restart" \
        $ethereum_bootnode_logfile

