Initial recipe for NUT-2.7.4
[unleashed-userland.git] / components / sysutils / nut / files / nut.in
blobe083e6852ffc9af84274ff12e78ddf06da65c7f4
1 #!/sbin/sh
3 # Trivial (better is yet to come) SMF method script to start nut services
4 # Adapted for OpenIndiana userland from init.d script template in NUT sources
5 # Adaptation copyright (C) 2016 Jim Klimov
7 if [ -z "$SMF_FMRI" ]; then
8 echo "$0 must be called in SMF context!" &>2
9 exit 1
12 # smf(5)
13 . /lib/svc/share/smf_include.sh || exit
15 NUT_DIR="@USRDIR@"
16 NUT_SBIN_DIR="$NUT_DIR/sbin"
17 #NUT_SBIN_DIR="$NUT_DIR/sbin/@MACH64@"
18 NUT_RUN_DIR="/@NUTRUNDIR@"
19 NUTUSER="@NUTUSER@"
20 NUTGROUP="@NUTGROUP@"
21 CONFIG="/@NUTETCDIR@/nut.conf"
23 if [ -f "$CONFIG" ] ; then
24 . "$CONFIG"
27 ups_stop () {
28 pkill -n upsmon
29 pkill -n upsd
30 "${NUT_SBIN_DIR}"/upsdrvctl stop > /dev/null 2>&1
33 ups_start () {
34 if [ "$MODE" = "none" ];then
35 echo "No NUT mode set" >&2
36 exit $SMF_EXIT_ERR_CONFIG
39 # Default rights inspired by NUT scripts/Solaris/postinstall.in
40 mkdir -p "$NUT_RUN_DIR" && \
41 chown "root:$NUTGROUP" "$NUT_RUN_DIR" && \
42 chmod 770 "$NUT_RUN_DIR" \
43 || exit $SMF_EXIT_ERR_FATAL
45 if [ ! "$MODE" = "netclient" ];then
46 "${NUT_SBIN_DIR}"/upsdrvctl start #> /dev/null 2>&1
47 "${NUT_SBIN_DIR}"/upsd #> /dev/null 2>&1
49 "${NUT_SBIN_DIR}"/upsmon #> /dev/null 2>&1
52 case "$1" in
53 'start')
54 ups_start
57 'stop')
58 ups_stop
61 'restart')
62 ups_stop
63 while pgrep upsd > /dev/null
65 sleep 1
66 done
67 ups_start
69 'poweroff')
70 "${NUT_SBIN_DIR}"/upsmon -K >/dev/null 2>&1
71 if [ $? = 0 ]; then
72 echo "Shutting down the UPS ..."
73 #"${NUT_SBIN_DIR}"/upsdrvctl shutdown
77 echo ""
78 echo "Usage: '$0' {start | stop | restart }"
79 echo ""
80 exit $SMF_EXIT_ERR_CONFIG
82 esac
84 exit $?