<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2021 Jens Elkner.
-->

<service_bundle type='manifest' name='LNFsnmp-export:default'>

<service name='network/snmp-export' type='service' version='1'>

	<create_default_instance enabled="false" />

	<single_instance />

	<!-- Wait for network interfaces to be initialized.  -->
	<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>

	<exec_method type='method' name='start'
		exec='/usr/sbin/snmp-export %{config/start_args} --config.file=%{config/file}'
		timeout_seconds='60'>
		<method_context>
			<method_credential user='daemon' group='daemon' />
			<!-- doesn't hurt if not used (24K) -->
			<method_environment>
				<envvar name='LD_PRELOAD' value='libmtmalloc.so'/>
			</method_environment>
		</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' />
		<!-- Where to store temporary data -->
		<propval name='file' type='astring' value='/etc/snmp-export-default.yml' />
		<!--
Any options to pass verbatim to the exporter. See 'snmp-export -h'.

Check operational state e.g. via http://localhost:9116/
		-->
		<property name="start_args" type="astring">
			<astring_list>
				<value_node value='--loglevel=info' />
			</astring_list>
		</property>
	</property_group>

	<property_group name='startd' type='framework'>
		<!-- golang bloat usually has no daemon mode =8-( -->
		<propval name='duration' type='astring' value='child' />
		<propval name='ignore_error' type='astring' value='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.snmp-export' >>/etc/user_attr
	-->
	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.snmp-export' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.snmp-export' />
	</property_group>

	<stability value='Evolving' />

	<template>
		<common_name>
			<loctext xml:lang='C'>Prometheus SNMP exporter</loctext>
		</common_name>
		<documentation>
			<doc_link name='snmp-export'
				uri='https://github.com/jelmd/snmp-export/blob/main/README.md' />
		</documentation>
	</template>
</service>

</service_bundle>
