File: svc-nut-server.in

package info (click to toggle)
nut 2.8.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,356 kB
  • sloc: ansic: 123,904; sh: 14,718; cpp: 12,558; makefile: 5,212; python: 1,114; perl: 855; xml: 47
file content (88 lines) | stat: -rwxr-xr-x 2,008 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/sbin/sh

# Trivial (better is yet to come) SMF method script to start nut services
# Adapted for OpenIndiana userland from init.d script template in NUT sources
# Adaptation copyright (C) 2016 Jim Klimov

if [ -z "$SMF_FMRI" ]; then
	echo "$0 must be called in SMF context!" >&2
	exit 1
fi

# smf(5)
. /lib/svc/share/smf_include.sh || exit

prefix="@prefix@"
NUT_DIR="@prefix@"
NUT_SBIN_DIR="$NUT_DIR/sbin"
NUT_LIB_DIR="${NUT_DIR}/lib"

NUT_RUN_DIR="`svcprop -p nut/NUT_RUN_DIR $SMF_FMRI`" \
&& [ -n "$NUT_RUN_DIR" ] \
|| NUT_RUN_DIR="@ALTPIDPATH@"

CONFIG="@CONFPATH@/nut.conf"

NUTUSER="`svcprop -p nut/NUTUSER $SMF_FMRI`" \
&& [ -n "$NUTUSER" ] \
|| NUTUSER="@RUN_AS_USER@"

NUTGROUP="`svcprop -p nut/NUTGROUP $SMF_FMRI`" \
&& [ -n "$NUTGROUP" ] \
|| NUTGROUP="@RUN_AS_GROUP@"

# We anticipate some tighter integration with SMF later:
#NUT_QUIET_INIT_UPSNOTIFY=true
#export NUT_QUIET_INIT_UPSNOTIFY

if [ -f "$CONFIG" ] ; then
	. "$CONFIG"
fi

create_run_dir () {
	# Default rights inspired by NUT scripts/Solaris/postinstall.in
	#mkdir -p "@PIDPATH@" # (for privileged processes - not upsd)
	mkdir -p "$NUT_RUN_DIR" && \
	chown "root:$NUTGROUP" "$NUT_RUN_DIR" && \
	chmod 770 "$NUT_RUN_DIR" \
	|| exit $SMF_EXIT_ERR_FATAL
}

ups_start () {
	create_run_dir

	if [ "$MODE" = "none" ];then
		echo "No NUT mode set, not starting anything" >&2
		exit 1
	fi

	if [ "$MODE" != "netclient" ] ; then
		# In this distribution, UPS drivers are wrapped by service instances
		#LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsdrvctl" start #> /dev/null 2>&1
		LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsd" #> /dev/null 2>&1
	fi
}

case "$1" in
'start')
	ups_start
	;;

'refresh'|'reload')
	LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}/upsd" -c reload
	;;

"create_run_dir")
	# Mostly provided for the sake of nut-driver service
	create_run_dir
	;;

*)
	echo ""
	echo "Usage: '$0' {start}"
	echo ""
	exit $SMF_EXIT_ERR_CONFIG
	;;
esac

exit $?