*New 11.4 series Release:
2020-07-03: XigmaNAS 11.4.0.4.7633 - released!

*New 12.1 series Release:
2020-04-17: XigmaNAS 12.1.0.4.7542 - released


We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

[SOLVED] Script to check & restart UPS service periodically?

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
superman8822
Starter
Starter
Posts: 17
Joined: 05 Sep 2012 15:50
Status: Offline

[SOLVED] Script to check & restart UPS service periodically?

#1

Post by superman8822 »

Hi,
My UPS (Eaton E Series NV USB, using driver blazer_usb) periodically disconnected from Nas4Free 9.1.0.1.636.

Is it possible to restart the UPS service through cron (let say every 15 mins) or even better: have it restart everytime
it's get disconnected?

Thanks :)
Last edited by al562 on 22 Feb 2013 17:59, edited 1 time in total.
Reason: Adjusted Subject. Added [SOLVED] Tag.

al562
Advanced User
Advanced User
Posts: 221
Joined: 12 Dec 2012 08:02
Location: New Jersey, U.S.A.
Contact:
Status: Offline

Re: Is it possible to restart UPS services periodically ?

#2

Post by al562 »

Hi Superman8822,

You would have to write a script that checks the status and then restarts it if it is not running. Before you do that you should examine the logs and try to figure out why it disconnects, there may be a better driver or some other way around the problem.

Regards,
Al

superman8822
Starter
Starter
Posts: 17
Joined: 05 Sep 2012 15:50
Status: Offline

Re: Is it possible to restart UPS services periodically ?

#3

Post by superman8822 »

Hi Al,
Thanks again for your reply :)

I have no idea why it keep disconnected periodically. Adding pollinterval=15 make it disconnect much seldom, but it still disconnected sometime.
I think the driver is already correct. So my solution is cron this little script every 5 mins:

!/bin/bash
CHECK=$0
SERVICE=blazer_usb
DATE=`date`
OUTPUT=$(ps ax | grep -v grep | grep -v $CHECK |grep $SERVICE)
echo $OUTPUT
if [ "${#OUTPUT}" -gt 0 ] ;
then echo "$DATE: $SERVICE service running, everything is fine"
else /etc/rc.d/nut restart
fi

I got the script googling and modified it to suit my need. It works great.

Again, hope it help somebody someday somewhere who landed in this page searching for solution for the similiar problem :)

armandh
Advanced User
Advanced User
Posts: 403
Joined: 23 Jun 2012 04:15
Location: St Louis County Missouri USA
Status: Offline

Re: Is it possible to restart UPS services periodically ?

#4

Post by armandh »

since some one already invented that wheel I suspect it is not a unique problem.
thanks for posting the fix
4 thread 3300 Mhz Intel i3, 1 TB ZFS mirror, available RAM 7.823 Gb, 64 bit NAS4Free 9.1.0.1 rev 573 [88 watts, 48 Mbps]
2 thread 1600 Mhz atom/ion, 1 TB ZFS mirror, available RAM 3.083 Gb, 64 bit NAS4Free-9.1.0.1 rev 573 [27 watts, 35 Mbps]
2 thread 3900 Mhz AMD A6-6400K, 2 TB ZFS Mirror, available RAM 7.557 Gb, 64 bit Nas4Free 9.3.0.2.1771 [89 watts, 68 Mbps]

superman8822
Starter
Starter
Posts: 17
Joined: 05 Sep 2012 15:50
Status: Offline

Re: Is it possible to restart UPS services periodically ?

#5

Post by superman8822 »

Hi Armandh,
I believe it's not a unique problem because googling found me many similiar posts, but the original script is to restart any service that given as a parameter (not connected to this particular problem), but I modify it only check and restart blazer_usb (NUT) service :)

al562
Advanced User
Advanced User
Posts: 221
Joined: 12 Dec 2012 08:02
Location: New Jersey, U.S.A.
Contact:
Status: Offline

Re: [SOLVED] Script to check & restart UPS service periodica

#6

Post by al562 »

Hi Superman8822,

Thanks for posting your script, I'm sure it will help many people.
I am marking this [SOLVED] and moving it permanently into the scripts sub-forum where it will be easily found in future.

Regards,
Al

Post Reply

Return to “Scripts and shell tips”