#!/bin/sh /etc/rc.common
# Copyright (c), NETGEAR, Inc.
# 350 East Plumeria, San Jose California, 95134, U.S.A.
# All rights reserved.
#
# This software is the confidential and proprietary information of
# NETGEAR, Inc. ("Confidential Information").  You shall not
# disclose such Confidential Information and shall use it only in
# accordance with the terms of the license agreement you entered into
# with NETGEAR.

START=95

USE_PROCD=1

PROG="/opt/netgear/usr/bin/xagent"
SN=`/opt/netgear/bin/system -g serial_number`
MODEL=`/opt/netgear/bin/system -g model_name`
ARGS="-c /etc/xagent.conf --disable_console --ca_file /opt/netgear/etc/certs/ca-bundle-mega.crt --log_info --log_file /tmp/xagent.log --log_file_size 1M --log_file_cnt 3 --hardware_id $SN --model_id $MODEL"
LIB_DIR="/opt/netgear/usr/lib"

start_service() {
        # Check the fix the agent conf (xagent.conf and insight-cli.conf)
        # before starting the service
        LD_LIBRARY_PATH=$LIB_DIR /opt/netgear/usr/bin/insight-cli check-fix-config

        procd_open_instance

        procd_set_param command $PROG $ARGS
        # respawn automatically if something died, be careful if you have an alternative process supervisor
        # if process dies sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped
        procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}

        procd_set_param env LD_LIBRARY_PATH=$LIB_DIR
        procd_set_param limits core="32MB"
        procd_set_param stdout 1 # forward stdout of the command to logd
        procd_set_param stderr 1 # forward stderr of the command to logd
        procd_set_param user root
        procd_set_param pidfile /var/run/xagent.pid

        procd_close_instance
}
