howto allow anyone to poweroff?

hw hw at
Fri Aug 9 14:26:07 UTC 2019

Polytropon <freebsd at> writes:

> On Thu, 8 Aug 2019 09:46:18 +0800, Erich Dollansky wrote:
>> Hi,
>> On Wed, 7 Aug 2019 18:37:35 +0200
>> hw <hw at> wrote:
>> > Hi,
>> > 
>> > is there a way to allow ordinary users to poweroff a machine?  I'd
>> > like to automatically poweroff PXE booted clients once the user that
>> > was logged in logs out after using it.
>> an unconventional way would be to have a cron job checking if someone
>> is locked in an power off the machine if none is logged in. You do not
>> have problems with the access rights but might run into the problem
>> that the machine shutsdown when somebody just has arrived at the
>> machine.
>> You also can catch the logout event and shut the machine down then. It
>> is the problem with the access right again.
> TO extend this idea, you could parse the output of programs
> like "w" to check for reamining interactive users. If the
> last one has logged out in a cron-controlled specific time
> window, the system could perform a shutdown. Hoewever, the
> problem described above will remain. :-)


The diskless clients are very unlikely to ever have more than a single
user, and a lost user who isn't using the machine shouldn't prevent it
from shutting down after all users using it have logged out.

Shutting down the machine right away when the user has logged out is
probably not a good idea because someone else (not so likely) or the
same user (more likely) might want to log in again right away.  Or it
may be a great idea because chances are that the user wanted to relog
because of some issue they are hoping to fix by relogging, in which case
it can be best to shutdown before allowing them to log in again.
However, they could decide that for themselves if the waiting time
before the shutdown is short (or press Ctrl+Alt+Del).

So how do I make it so that after maybe 3 minutes the user which has
used an X session has logged out, the machine shuts down?  The shell of
the user is set to startx, and I don't want to poll like every 3 minutes
if xfreerdp is still running ...

There is also the question how to shut down the machine after it has
not been used for a while, like an hour or so, while the user is still
logged in.

In any case, when a user logs out, there is no way to shut down the
machine other than holding the power button or pulling the plug, and
that sucks.

So far, I have only a startup script that initiates a shutdown after 500
minutes and am thinking to change it to a fixed time of day.

More information about the freebsd-questions mailing list