<div dir="ltr"><div>Cheers,<br></div><div><br></div><div>At least a few things that DO NOT seem right upon quick reading are:</div><div><br></div><div>* upsmon.conf:</div><div>
<pre><code>RUN_AS_USER root
</code></pre><div>Should not normally be required: when started as root, upsmon splits into unprivileged process for most of the work and leaves the shutdown handler running as root; with this setting you get it all running as root which is potentially unsafe.<br></div><div><br></div><div>* upsmon.conf:</div><div>
<pre><code></code></pre></div>

<pre><code>MONITOR qnapups<span>@localhost</span> <span>1</span> admin <span>123456</span> master
MONITOR qnapups<span>@192</span><span>.168</span><span>.222</span><span>.252</span> <span>3493</span> admin <span>123456</span> slave
<code>MINSUPPLIES <span>1</span></code>
</code></pre>

</div><div>Do you have two UPSes powering this system, or are you trying to monitor the same one by localhost and LAN IP addresses? Note that the number ("1" in the first line) is how many power sources of the current system that UPS powers (e.g. you may monitor remote UPSes in some branch office without critically reacting to their state by setting 0 here).</div>So the second line has the other UPS feed 3494 power sources of this system while you only require one to be powered reliably and stay calm ;) <br><div>I suppose here you meant the port - it should be a colon-separated suffix after the IP address (IIRC), and 3493 is the IANA registered default for NUT so not needed at all here.</div><div><br></div><div>
<div>The master/slave regards direct connection to the UPS (does *this* 
system control it, including a power-cut command, or a remote one does?)</div><div>
</div>

</div><div><br></div><div>* I did not use upssched much myself so do not feel qualified to comment; however pipe and lock files may better belong in /var/state/ups, /var/run/nut, /tmp or /dev/shm - preferably in a tmpfs to avoid hitting real storage with I/O that should not persist across reboots:</div><div><br></div><div>
<pre><code>PIPEFN <span>/</span>etc<span>/</span>nut<span>/</span>upssched.pipe
LOCKFN <span>/</span>etc<span>/</span>nut<span>/</span>upssched.lock</code></pre>

</div><div>While it should not be "fatal" to have them under /etc/nut as long as the processes involved have access there (in your case, ones already running as root), generally the daemon process should only have read-only access to its configuration files and their directory - to avoid having it exploited to overwrite the configs to something more sinister.</div><div><br></div><div>* FWIW<code><span> upsmon.conf</span></code> should not be world-readable as it has a copy of the passwords. Generally ups.conf also - it may be sensitive depending on protocols involved (snmp communities, netxml/ipmi/... logins...)<br></div><div><br></div><div>* admin/123456 - this should be set in upsd.users so not sure how much QNAP intervenes into the content of that config file to be "not working" otherwise. These are NUT accounts, not OS ones.<br></div><div><br></div><div>Hope this helps,</div><div>Jim Klimov</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 12, 2023 at 10:54 AM Rafael Reinoso via Nut-upsuser <<a href="mailto:nut-upsuser@alioth-lists.debian.net">nut-upsuser@alioth-lists.debian.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-956133932952752290">




<div dir="ltr">
<p>Now I have this in /etc/nut/upsmon.conf (my QNAP NAS wants admin and 123456 or not working)</p>
<p><br>
</p>
<pre><code>RUN_AS_USER root
MONITOR qnapups<span>@localhost</span> <span>1</span> admin <span>123456</span> master
MONITOR qnapups<span>@192</span><span>.168</span><span>.222</span><span>.252</span> <span>3493</span> admin <span>123456</span> slave
MINSUPPLIES <span>1</span>
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ <span>5</span>
POLLFREQALERT <span>5</span>
HOSTSYNC <span>15</span>
DEADTIME <span>15</span>
POWERDOWNFLAG <span>/</span>etc<span>/</span>killpower

NOTIFYFLAG ONLINE SYSLOG<span>+</span><span>EXEC</span>
NOTIFYFLAG ONBATT SYSLOG<span>+</span><span>EXEC</span>
NOTIFYFLAG LOWBATT SYSLOG<span>+</span><span>EXEC</span>
NOTIFYFLAG REPLBATT SYSLOG<span>+</span><span>EXEC</span>
NOTIFYCMD <span>/</span>usr<span>/</span>sbin<span>/</span>upssched

RBWARNTIME <span>43200</span>
NOCOMMWARNTIME <span>300</span>
FINALDELAY <span>5<br></span></code></pre>
<pre><code>
</code></pre>
<p>And in /etc/nut/upssched.conf (changed from 2 min to 4 min)</p>
<p style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</p>
<pre><code>CMDSCRIPT <span>/</span>etc<span>/</span>nut<span>/</span>upssched<span>-</span>execscript.sh

PIPEFN <span>/</span>etc<span>/</span>nut<span>/</span>upssched.pipe
LOCKFN <span>/</span>etc<span>/</span>nut<span>/</span>upssched.lock

<span>AT</span> ONBATT <span>*</span> <span>START</span><span>-</span>TIMER shutdown_onbatt <span>240</span>
<span>AT</span> ONBATT <span>*</span> <span>EXECUTE</span> info_onbatt

<span>AT</span> ONLINE <span>*</span> CANCEL<span>-</span>TIMER shutdown_onbatt
<span>AT</span> ONLINE <span>*</span> <span>EXECUTE</span> ups<span>-</span>back<span>-</span><span>on</span><span>-</span>power

<span>AT</span> LOWBATT <span>*</span> <span>EXECUTE</span> shutdown_lowbatt

<span>AT</span> REPLBATT <span>*</span> <span>EXECUTE</span> replace_batt
<br>
</code></pre>
<p>And in /etc/nut/upssched-execscript.sh</p>
<p style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</p>
<pre><code><span>#! /bin/sh</span>
<span>case</span> <span>$1</span> <span>in</span>
    shutdown_onbatt)
        logger -t upsmon[upssched] <span>"shutdown_onbatt): Triggering shutdown after 4 minutes on battery"</span>
        /sbin/shutdown -h +0
        ;;

    shutdown_lowbatt)
        logger -t upsmon[upssched] <span>"shutdown_lowbatt): Triggering shutdown when battery.charge.low is under 50%"</span>
        /sbin/shutdown -h +0
        ;;

    info_onbatt)
        logger -t upsmon[upssched] <span>"info_onbatt): Now on battery"</span>
        ;;

    ups-back-on-power)
        logger -t upsmon[upssched] <span>"ups-back-on-power): UPS back on power"</span>
        ;;

    replace_batt)
        message=<span>"Quick self-test indicates battery requires replacement"</span>
        logger -t upsmon[upssched] <span>"replace_batt): <span>$message</span>"</span>
        ;;

    *)
        logger -t upsmon[upssched] <span>"*) = Unrecognized command: <span>$1</span>"</span>
        ;;
<span>esac<br></span></code></pre>
<pre><code><span></span></code><code>
</code></pre>
<p>And in /etc/nut/ups.conf</p>
<p><br>
</p>
<pre><code>[qnapups]
    driver = usbhid-ups
    port = <span>auto</span>
    desc = <span>"UPS"</span>
    ignorelb
    <span>override</span>.battery.charge.low=<span>50</span>
</code></pre>
<p><br>
</p>
<p><br>
</p>
<p>So I have these files</p>
<pre><code>[<span>root@ipfire2</span> <span>nut</span>]<span># pwd</span>
<span>/etc/nut</span>
[<span>root@ipfire2</span> <span>nut</span>]<span># ls -la</span>
<span>total</span> <span>104</span>
<span>drwxr-xr-x</span>  <span>2</span> <span>root</span> <span>root</span>  <span>4096 </span><span>Jan</span> <span>10</span> <span>09</span><span>:23</span> <span>.</span>
<span>drwxr-xr-x</span> <span>50</span> <span>root</span> <span>root</span>  <span>4096 </span><span>Jan</span> <span>10</span> <span>10</span><span>:33</span> <span>..</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>1542 </span><span>Jan</span> <span>10</span> <span>09</span><span>:05</span> <span>nut.conf</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>1538 </span><span>Dec</span> <span>18</span>  <span>2020 </span><span>nut.conf.sample</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>4734 </span><span>Jan</span> <span>10</span> <span>09</span><span>:10</span> <span>ups.conf</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>4618 </span><span>Dec</span> <span>18</span>  <span>2020 </span><span>ups.conf.sample</span>
<span>-rw-r-----</span>  <span>1</span> <span>root</span> <span>root</span>  <span>4606 </span><span>Dec</span> <span>22</span> <span>08</span><span>:44</span> <span>upsd.conf</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>4578 </span><span>Dec</span> <span>18</span>  <span>2020 </span><span>upsd.conf.sample</span>
<span>-rw-r-----</span>  <span>1</span> <span>root</span> <span>root</span>  <span>2292 </span><span>Dec</span> <span>22</span> <span>07</span><span>:11</span> <span>upsd.users</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>2131 </span><span>Dec</span> <span>18</span>  <span>2020 </span><span>upsd.users.sample</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span> <span>15569</span> <span>Jan</span> <span>10</span> <span>10</span><span>:20</span> <span>upsmon.conf</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span> <span>15313</span> <span>Dec</span> <span>18</span>  <span>2020 </span><span>upsmon.conf.sample</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>4173 </span><span>Jan</span> <span>10</span> <span>10</span><span>:22</span> <span>upssched.conf</span>
<span>-rw-r--r--</span>  <span>1</span> <span>root</span> <span>root</span>  <span>3895 </span><span>Dec</span> <span>18</span>  <span>2020 </span><span>upssched.conf.sample</span>
<span>-rwxr-xr-x</span>  <span>1</span> <span>root</span> <span>root</span>   <span>810</span> <span>Jan</span> <span>10</span> <span>10</span><span>:29</span> <span>upssched-execscript.sh</span>
</code></pre>
<p>Do all that seem right to you?</p>
<br>
</div>

_______________________________________________<br>
Nut-upsuser mailing list<br>
<a href="mailto:Nut-upsuser@alioth-lists.debian.net" target="_blank">Nut-upsuser@alioth-lists.debian.net</a><br>
<a href="https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser" rel="noreferrer" target="_blank">https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser</a><br>
</div></blockquote></div>