<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
	file: /lib/svc/manifest/system/ipmimex.xml
	Run  'svcadm restart manifest-import' to activate if you copied the file
	to this location manually (i.e. not installed as part of a package).

    Copyright 2022 Jens Elkner.
-->

<service_bundle type='manifest' name='LNFipmimex'>

<service name='system/ipmimex' type='service' version='1'>

	<create_default_instance enabled="false" />

	<single_instance />

	<!-- Wait for network interfaces to be initialized so we can bind.  -->
	<dependency name='network' grouping='require_all' restart_on='refresh'
	    type='service'>
	    <service_fmri value='svc:/milestone/network:default'/>
	</dependency>

	<!-- Wait for all local filesystems to be mounted.  -->
	<dependency name='filesystem-local' grouping='require_all' restart_on='none'
	    type='service'>
	    <service_fmri value='svc:/system/filesystem/local:default'/>
	</dependency>

	<!-- Start ipmimex before vmagent -->
	<dependent name='vmagent' grouping='optional_all' restart_on='none'>
		<service_fmri value='svc:/application/database/vmagent'/>
	</dependent>

	<exec_method type='method' name='start'
		exec='/usr/sbin/ipmimex %{config/start_args} -d -l %{config/logfile} -p %{config/port}'
		timeout_seconds='10'>
		<method_context>
			<!-- Who knows, why one needs sysconfig privs to be able to
				query dcmi states. Someone had probably a bad day ....
				user='webservd' group='webservd' should be ok, too.
			-->
			<method_credential user='daemon' group='daemon'
				privileges='basic,sys_config,!proc_session,!proc_info,!file_link_any,{zone}:/var/log/ipmimex.log' />
		</method_context>
	</exec_method>

	<exec_method timeout_seconds='5' type='method' name='stop'
		exec=':kill -TERM' />

	<property_group name='config' type='application'>
		<stability value='Evolving' />
		<!-- Check operational state e.g. via http://localhost:9290/metrics -->
		<propval name='port' type='integer' value='9290' />
		<propval name='logfile' type='astring' value='/var/log/ipmimex.log' />
		<!-- Any options to pass verbatim to the agent. E.g. just power reading
			and overall scrapetime use '-c -n version,ipmi,process -PS' or for
			compact as possible, readings, only: '-c PoDNUT'
		-->
		<property name="start_args" type="astring">
			<astring_list>
				<value_node value='-c' />
				<value_node value='-N' /><!-- fix for SUN ILOMs -->
			</astring_list>
		</property>
	</property_group>

	<property_group name='startd' type='framework'>
		<!-- service mode is contract -->
		<propval name='duration' type='astring' value='contract' />
		<!-- sub-process core dumps shouldn't restart session -->
		<propval name='ignore_error' type='astring' value='core,signal' />
	</property_group>

	<!--
		Add all users, which should be able to manage this service
		into /etc/user_attr . E.g.:
		echo 'jdoe::::auths=solaris.smf.manage.ipmimex' >>/etc/user_attr
	-->
	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.ipmimex' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.ipmimex' />
	</property_group>

	<stability value='Evolving' />

	<template>
		<common_name>
			<loctext xml:lang='C'>
				ipmiex - a metrics exporter for IPMI driven BMCs.
			</loctext>
		</common_name>
		<documentation>
			<manpage title='ipmimex' section='8' manpath='/usr/share/man' />
			<doc_link name='github' uri='https://github.com/jelmd/ipmimex' />
		</documentation>
	</template>
</service>

</service_bundle>
