<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
#
# Copyright 2016 - 2019 Jim Klimov
# Template manifest for instantiated NUT drivers
#
-->

<service_bundle type='manifest' name='nut-driver'>

	<service name='system/power/nut-driver' type='service' version='1.1'>

	<!--
	  Wait for all local and usr filesystem to be mounted - project is
	  usually located in /usr/sbin.
	-->
		<dependency
		name='fs-local'
		type='service'
		grouping='require_all'
		restart_on='none'>
			<service_fmri value='svc:/system/filesystem/local' />
		</dependency>

		<dependency
		name='filesystem-usr'
		grouping='require_all'
		restart_on='none'
		type='service'>
			<service_fmri
		value='svc:/system/filesystem/usr:default'/>
		</dependency>

		<dependency
		name='config-files'
		type='path'
		grouping='require_all'
		restart_on='refresh'>
			<service_fmri value='file://localhost@CONFPATH@/ups.conf' />
		</dependency>

	<!--
	  Wait for syslog to be started in order to write system
	  messages from the kernel and drivers, where enabled.
	-->
		<dependency
		name='syslog'
		grouping='optional_all'
		restart_on='none'
		type='service'>
			<service_fmri
		value='svc:/system/system-log:default'/>
		</dependency>

	<!--
	  Wait for enumerator to have ensured that all configured sections
	  have a corresponding SMF instance. Do not restart all driver
	  instances if there was just a reconfiguration of enumerator.
	-->
		<dependency
		name='nut-driver-enumerator'
		grouping='optional_all'
		restart_on='error'
		type='service'>
			<service_fmri value='svc:/system/power/nut-driver-enumerator' />
		</dependency>

	<!--
	  Prerequisite for NUT upsd to be started, if it's enabled
	  Note that drivers are optional: if one fails to start, do not block
	  the upsd from publishing others.
	-->
		<dependent
		name='nut-service_needs_drivers'
		grouping='optional_all'
		restart_on='none'>
			<service_fmri value='svc:/system/power/nut-server' />
		</dependent>

	<!--
	  The nut start/stop methods.
	-->

		<exec_method
		type='method'
		name='start'
		exec='/sbin/sh -c &apos;NUTDEV="`@NUT_LIBEXECDIR@/nut-driver-enumerator.sh --get-device-for-service %i`" &amp;&amp; [ -n "$NUTDEV" ] || { echo "FATAL: Could not find a NUT device section for service unit %i" >&amp;2 ; exit 1 ; } ; @SBINDIR@/upsdrvctl %m "$NUTDEV"&apos;'
		timeout_seconds='0'/>

		<exec_method
		type='method'
		name='stop'
		exec='/sbin/sh -c &apos;NUTDEV="`@NUT_LIBEXECDIR@/nut-driver-enumerator.sh --get-device-for-service %i`" &amp;&amp; [ -n "$NUTDEV" ] || { echo "FATAL: Could not find a NUT device section for service unit %i" >&amp;2 ; exit 1 ; } ; @SBINDIR@/upsdrvctl %m "$NUTDEV"&apos;'
		timeout_seconds='60' />

		<property_group name='startd' type='framework'>
		<!--
		  Sub-process core dumps and external kill signals are not
		  considered errors, so the service should be restarted.
			-->
			<propval name='ignore_error' type='astring'
			 value='core,signal' />
		</property_group>

	<!-- Really unstable - this service should be evolved! -->
		<stability value='Unstable' />

		<template>
			<common_name>
				<loctext xml:lang='C'>
				NUT power device driver instance wrapper
				</loctext>
			</common_name>
			<documentation>
				<manpage title='upsdrvctl' section='8'
				manpath='/usr/share/man' />
				<manpage title='ups.conf' section='5'
				manpath='/usr/share/man' />
			</documentation>
		</template>
	</service>

</service_bundle>
