<?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='LNFvictoria-metrics:vmdb'>

<service name='application/database/vmdb' 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/vmdb %{config/start_args} -storageDataPath=%{config/db_path}'
		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' />
		<propval name='db_path' type='astring' value='/var/lib/vmdb' />
		<!--
Any options to pass verbatim to the server. See 'victoria-metrics -h'.

Interesting options/flags and their defaults: '-deleteAuthKey=secret'
'-forceFlushAuthKey=secret', '-forceMergeAuthKey=secret'
'-httpAuth.password=secret', '-httpAuth.username='
'-snapshotAuthKey=secret',
'-tls=false', '-tlsCertFile=""', '-tlsKeyFile=secret'
'-http.pathPrefix=', '-http.disableResponseCompression'
'-httpListenAddr=8428', '-graphiteListenAddr=', '-influxListenAddr='
'-opentsdbHTTPListenAddr=', '-opentsdbListenAddr='				# 4242
'-promscrape.config=', '-promscrape.disableCompression'
'-promscrape.disableKeepAlive=true'
'-retentionPeriod=1m'

Check operational state e.g. via http://localhost:8428/metrics
		-->
		<property name="start_args" type="astring">
			<astring_list>
				<value_node value='--selfScrapeInterval=10s' />
			</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.vmdb' >>/etc/user_attr
	-->
	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.vmdb' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.vmdb' />
	</property_group>

	<stability value='Evolving' />

	<template>
		<common_name>
			<loctext xml:lang='C'>
				Victoria Metrics server
			</loctext>
		</common_name>
		<documentation>
			<doc_link name='vmdb'
				uri='https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html' />
		</documentation>
	</template>
</service>

</service_bundle>
