File: svc-nut-logger.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 (75 lines) | stat: -rwxr-xr-x 1,791 bytes parent folder | download | duplicates (2)
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
#!/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-2025 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="@ALTPIDPATH@"
CONFIG="@CONFPATH@/nut.conf"
DAEMON_CONFIG="@CONFPATH@/upslog.conf"
NUTUSER="@RUN_AS_USER@"
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

if [ -s "$DAEMON_CONFIG" ] ; then
	. "$DAEMON_CONFIG"
else
	echo "Daemon config file '$DAEMON_CONFIG' not found or populated, not starting anything" >&2
	exit $SMF_EXIT_ERR_CONFIG
fi

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

	if [ x"${UPSLOG_ARGS-}" = x ; then
		echo "UPSLOG_ARGS not found or populated in configuration, not starting anything" >&2
		exit $SMF_EXIT_ERR_CONFIG
	fi

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

	# Fork and background regardless of logging to a file or stdout (-)
	LD_LIBRARY_PATH="${NUT_LIB_DIR}:$LD_LIBRARY_PATH" "${NUT_SBIN_DIR}"/upslog -B $UPSLOG_ARGS #> /dev/null 2>&1
}

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

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

exit $?