<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
	file: /lib/svc/manifest/application/management/ilomex.xml

	To remove this service, use:
		rm -f /lib/svc/manifest/application/ilomex.xml
		svcadm restart manifest-import
	To re-import and run, use:
		cp etc/ilomex.xml /lib/svc/manifest/application/management/ilomex.xml
		svcadm restart manifest-import
		svcadm enable ilomex

	The ilomex package does this on install/uninstall automatically.

    Copyright 2025 Jens Elkner.
-->

<service_bundle type='manifest' name='LNFilomex:ilomex'>

<service name='application/management/ilomex' 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 ilomex before vmagent (if there is one) -->
	<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/ilomex %{config/start_args} -i %{config/file} -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/ilomex.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='9300' />
		<propval name='logfile' type='astring' value='/var/log/ilomex.log' />
		<propval name='file' type='astring' value='/etc/ilomex.conf' />
		<!-- Any options to pass verbatim to the agent. E.g.
			svccfg -s ilomex:default setprop 'config/start_args = ( "-cn" "version" )'
			svccfg -s ilomex:default setprop 'config/file = "/local/ilomex.conf" '
		-->
		<property name="start_args" type="astring">
			<astring_list>
				<value_node value='-c' />
				<value_node value='-n' />
				<value_node value='version' />
			</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.ilomex' >>/etc/user_attr
	-->
	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.ilomex' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.ilomex' />
	</property_group>

	<stability value='Evolving' />

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

</service_bundle>
