#!/bin/sh

# PROVIDE: wazuh_agent
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
# wazuh_agent_enable (bool):	Set to NO by default.
# 				Set it to YES to enable Wazuh Agent.
#

. /etc/rc.subr

name="wazuh_agent"	# How the service will be invoked from service
rcvar="${name}_enable" 	# The variable in rc.conf that will allow this service to run

load_rc_config $name 	# Loads the config file, if relevant.

: ${wazuh_agent_enable:="NO"}

command="/var/ossec/bin/ossec-control"
extra_commands="status"

start_cmd="wazuh_agent_start"
stop_cmd="wazuh_agent_stop"
status_cmd="wazuh_agent_status"

wazuh_agent_start() {
	echo -n "Starting Wazuh: "
	${command} start > /dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		echo success
	else
		echo failure
	fi
	echo
	return $RETVAL
}

wazuh_agent_stop() {
	echo -n "Stopping Wazuh: "
	${command} stop > /dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		echo success
	else
		echo failure
	fi
	echo
	return $RETVAL
}

wazuh_agent_status() {
        ${command} status
}

run_rc_command "$@"

