<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
#
# Copyright 2016-2017 Jim Klimov
# Service for common startup or shutdown of NUT-related services
#
-->

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

	<service name='system/power/nut' type='service' version='1'>

	<!--
	  Configure a default instance for the service since it doesn't
	  require additional configuration intervention before it starts.
	-->
		<create_default_instance enabled='true' />

	<!--
	  Not all deployments have both the drivers+data server and client
	  on the same box, so this service only triggers whatever is enabled
	  and waits for other system resources according to dependencies of
	  those actual services.
	-->
		<dependency
		name='syslog'
		grouping='optional_all'
		restart_on='error'
		type='service'>
			<service_fmri value='svc:/system/power/nut-server:default'/>
			<service_fmri value='svc:/system/power/nut-monitor:default'/>
		</dependency>

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

		<!-- The startup is expected to trigger enabled dependency services
		     and not-trigger those which were not administratively enabled.
		     There is nothing to do by itself, so it is not-persistent. -->
		<exec_method
		type='method'
		name='start'
		exec='/bin/true'
		timeout_seconds='60'/>

		<!-- The shutdown temporarily-disables all components (if they were
		     enabled and running in the first place, no-op otherwise) -->
		<exec_method
		type='method'
		name='stop'
		exec='/usr/sbin/svcadm disable -ts svc:/system/power/nut-monitor:default || /bin/true ; /usr/sbin/svcadm disable -ts svc:/system/power/nut-server:default || /bin/true ; @SBINDIR@/upsdrvsvcctl stop || /bin/true ; /bin/true'
		timeout_seconds='120' />

		<!-- When users "refresh nut" they are likely interested
		     in a new config being applied... -->
		<exec_method
		type='method'
		name='refresh'
		exec='@NUT_LIBEXECDIR@/nut-driver-enumerator.sh'
		timeout_seconds='0'/>

		<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' />
		<!--
		  A transient service executes the start method once and does
		  not execute it again if the method exits with $SMF_EXIT_OK.
			-->
			<propval name='duration' type='astring' value='transient' />
		</property_group>

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

		<template>
			<common_name>
				<loctext xml:lang='C'>
				Service for common startup or shutdown of NUT-related services
				</loctext>
			</common_name>
			<documentation>
				<manpage title='upsdrvctl' section='8'
				manpath='/usr/share/man' />
				<manpage title='upsd' section='8'
				manpath='/usr/share/man' />
				<manpage title='ups.conf' section='5'
				manpath='/usr/share/man' />
				<manpage title='upsd.conf' section='5'
				manpath='/usr/share/man' />
				<manpage title='upsd.users' section='5'
				manpath='/usr/share/man' />
			</documentation>
		</template>
	</service>

</service_bundle>
