0

Does anybody know how to stop a service when there is a power failure using NUT?
I made a custom script like this, the problem is that the script user (NUT) does not have root permissions to stop the service.
I want to stop the boinc-client right after a power failure, so that i do not drain the batteries and start the generator before it's really necessary.

#! /bin/bash
# UPS notify script.

if [$NOTIFYTYPE == "ONBATT"]
then

    /etc/init.d/boinc-client stop
fi

/usr/bin/mail -s "UPS '$UPSNAME': $NOTIFYTYPE" [email protected] <<END
$*
END
4
  • 1
    Run man sudo.
    – user143703
    Oct 27, 2014 at 20:33
  • 2
    +1 for displaying "bash nut" on my monitor. Oct 27, 2014 at 20:34
  • Server does not run SUDO.
    – HyperDevil
    Oct 27, 2014 at 20:59
  • 1
    Using sudo will be the best route. Oct 27, 2014 at 22:07

2 Answers 2

0

This looks just fine.

You have two options, one better than the other.

The first and best option is to use sudo. Allow noninteractive nopasswd sudo for the user the script is running as (specify the path of the script as the allowed command), and shove a sudo in front of the stop command.

The other option is to use unix permissions. Ensure the owner of the script is root, and its group is something the running user has access to (you might have to create a new group). Make it suid, give execute access to the group, and you're good to go (but make sure the group has not got write access, or you will have a security vulnerability).

-1

You could have a cron job with root permission checking for a file /tmp/poweroutage every 10 seconds and kill boinc once you see it. I agree that working on permissions may be preferable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .