Mailing List Archive

ACPI
I've been following the Wiki to configure automatic shutdown and
wakeup with rtc clock, but I can't get this accomplished:
'Then add mythtv and any other uses you wish to the "wheel" group.'
There is no Wheel Group, is this even relevant? I'm logging out (because
I'm using the "check_login.sh") but the box does not shut down (it passed
the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
combined FE/BE. TIA Daryl
Re: ACPI [ In reply to ]
On Fri, 11 Sep 2020 at 20:18, Daryl McDonald <darylangela@gmail.com> wrote:

> I've been following the Wiki to configure automatic shutdown and
> wakeup with rtc clock, but I can't get this accomplished:
> 'Then add mythtv and any other uses you wish to the "wheel" group.'
> There is no Wheel Group, is this even relevant? I'm logging out (because
> I'm using the "check_login.sh") but the box does not shut down (it passed
> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
> combined FE/BE. TIA Daryl
>

The wheel group is the historic name for what is now usually called the
sudo group. The idea is that you can just add users to the group instead
of configuring them individually in /etc/sudoers. Most distributions will
ship an /etc/sudoers file with:

%sudo ALL=(ALL:ALL) ALL

in it, which makes this work. Presumably in terms of what you're trying to
accomplish, this is because the automatic shutdown will be done by the
mythtv user via sudo as:

sudo shutdown -h now

Cheers, Ian
Re: ACPI [ In reply to ]
On Fri, Sep 11, 2020 at 1:18 PM Daryl McDonald <darylangela@gmail.com>
wrote:

> I've been following the Wiki to configure automatic shutdown and
> wakeup with rtc clock, but I can't get this accomplished:
> 'Then add mythtv and any other uses you wish to the "wheel" group.'
> There is no Wheel Group, is this even relevant? I'm logging out (because
> I'm using the "check_login.sh") but the box does not shut down (it passed
> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
> combined FE/BE. TIA Daryl
>
"wheel" is either an old UNIX or BSD convention that has been in most new
distributions replaced with the "sudo" group.\

Not quite sure what your level of familiarity is with *nix, but basically 2
lines above that in the wiki it basically reads "do whatever is needed to
make the mythtv user able to run sudo without a password, perhaps for 1
command, or everything by using the (theoretically) preexisting group that
has historically done this (wheel)".

Hope this helps,
Mike
Re: ACPI [ In reply to ]
I never got it to work, but I had the extra complication of a secondary
backend. I don't think the published walk through is current and it could
be written better.

Steve Greene
(301) 842-8923
historicity.co
An independent archival professional specializing in still photography,
moving images and recorded sound.


On Fri, Sep 11, 2020 at 3:34 PM Mike Hodson <mystica@gmail.com> wrote:

> On Fri, Sep 11, 2020 at 1:18 PM Daryl McDonald <darylangela@gmail.com>
> wrote:
>
>> I've been following the Wiki to configure automatic shutdown and
>> wakeup with rtc clock, but I can't get this accomplished:
>> 'Then add mythtv and any other uses you wish to the "wheel" group.'
>> There is no Wheel Group, is this even relevant? I'm logging out (because
>> I'm using the "check_login.sh") but the box does not shut down (it passed
>> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
>> combined FE/BE. TIA Daryl
>>
> "wheel" is either an old UNIX or BSD convention that has been in most new
> distributions replaced with the "sudo" group.\
>
> Not quite sure what your level of familiarity is with *nix, but basically
> 2 lines above that in the wiki it basically reads "do whatever is needed to
> make the mythtv user able to run sudo without a password, perhaps for 1
> command, or everything by using the (theoretically) preexisting group that
> has historically done this (wheel)".
>
> Hope this helps,
> Mike
>
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users@mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org
>
Re: ACPI [ In reply to ]
On Fri, 11 Sep 2020 20:29:02 +0100, you wrote:

>On Fri, 11 Sep 2020 at 20:18, Daryl McDonald <darylangela@gmail.com> wrote:
>
>> I've been following the Wiki to configure automatic shutdown and
>> wakeup with rtc clock, but I can't get this accomplished:
>> 'Then add mythtv and any other uses you wish to the "wheel" group.'
>> There is no Wheel Group, is this even relevant? I'm logging out (because
>> I'm using the "check_login.sh") but the box does not shut down (it passed
>> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
>> combined FE/BE. TIA Daryl
>>
>
>The wheel group is the historic name for what is now usually called the
>sudo group. The idea is that you can just add users to the group instead
>of configuring them individually in /etc/sudoers. Most distributions will
>ship an /etc/sudoers file with:
>
>%sudo ALL=(ALL:ALL) ALL
>
>in it, which makes this work. Presumably in terms of what you're trying to
>accomplish, this is because the automatic shutdown will be done by the
>mythtv user via sudo as:
>
>sudo shutdown -h now
>
>Cheers, Ian

The problem with "sudo shutdown -h now" is that it will pop up a
request for a password. Which is why you need to add sudoer
configuration for your shutdown script to allow it to be run by sudo
without a password. So the "ACPI Shutdown" Wiki page tells you to add
this to the sudoers config:

%mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh

as that has the "NOPASSWD:" option.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: ACPI [ In reply to ]
On Fri, Sep 11, 2020 at 10:21 PM Stephen Worthington <
stephen_agent@jsw.gen.nz> wrote:

> On Fri, 11 Sep 2020 20:29:02 +0100, you wrote:
>
> >On Fri, 11 Sep 2020 at 20:18, Daryl McDonald <darylangela@gmail.com>
> wrote:
> >
> >> I've been following the Wiki to configure automatic shutdown and
> >> wakeup with rtc clock, but I can't get this accomplished:
> >> 'Then add mythtv and any other uses you wish to the "wheel" group.'
> >> There is no Wheel Group, is this even relevant? I'm logging out (because
> >> I'm using the "check_login.sh") but the box does not shut down (it
> passed
> >> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
> >> combined FE/BE. TIA Daryl
> >>
> >
> >The wheel group is the historic name for what is now usually called the
> >sudo group. The idea is that you can just add users to the group instead
> >of configuring them individually in /etc/sudoers. Most distributions will
> >ship an /etc/sudoers file with:
> >
> >%sudo ALL=(ALL:ALL) ALL
> >
> >in it, which makes this work. Presumably in terms of what you're trying
> to
> >accomplish, this is because the automatic shutdown will be done by the
> >mythtv user via sudo as:
> >
> >sudo shutdown -h now
> >
> >Cheers, Ian
>
> The problem with "sudo shutdown -h now" is that it will pop up a
> request for a password. Which is why you need to add sudoer
> configuration for your shutdown script to allow it to be run by sudo
> without a password. So the "ACPI Shutdown" Wiki page tells you to add
> this to the sudoers config:
>
> %mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh
>

I have this in the sudoers file, with the addition of
/usr/bin/checklogin.sh

>
> as that has the "NOPASSWD:" option.
>

I also just noticed some bad pathways in setup, /usr/local/bin where it
should have been /usr/bin and visa-versa, maybe it will turn off tonight,
thanks all!
Re: ACPI [ In reply to ]
Still no joy. When I ran "sudo visudo" the comments said "consider creating
a sudoers.d file" (or something similar) which I didn't because the wiki
saed add this to the end of the file. Should I try the former?

On Fri, Sep 11, 2020 at 10:41 PM Daryl McDonald <darylangela@gmail.com>
wrote:

>
>
> On Fri, Sep 11, 2020 at 10:21 PM Stephen Worthington <
> stephen_agent@jsw.gen.nz> wrote:
>
>> On Fri, 11 Sep 2020 20:29:02 +0100, you wrote:
>>
>> >On Fri, 11 Sep 2020 at 20:18, Daryl McDonald <darylangela@gmail.com>
>> wrote:
>> >
>> >> I've been following the Wiki to configure automatic shutdown and
>> >> wakeup with rtc clock, but I can't get this accomplished:
>> >> 'Then add mythtv and any other uses you wish to the "wheel" group.'
>> >> There is no Wheel Group, is this even relevant? I'm logging out
>> (because
>> >> I'm using the "check_login.sh") but the box does not shut down (it
>> passed
>> >> the previous test in the wiki). I'm using myth v 31 on Ubuntu 20.04
>> >> combined FE/BE. TIA Daryl
>> >>
>> >
>> >The wheel group is the historic name for what is now usually called the
>> >sudo group. The idea is that you can just add users to the group instead
>> >of configuring them individually in /etc/sudoers. Most distributions
>> will
>> >ship an /etc/sudoers file with:
>> >
>> >%sudo ALL=(ALL:ALL) ALL
>> >
>> >in it, which makes this work. Presumably in terms of what you're trying
>> to
>> >accomplish, this is because the automatic shutdown will be done by the
>> >mythtv user via sudo as:
>> >
>> >sudo shutdown -h now
>> >
>> >Cheers, Ian
>>
>> The problem with "sudo shutdown -h now" is that it will pop up a
>> request for a password. Which is why you need to add sudoer
>> configuration for your shutdown script to allow it to be run by sudo
>> without a password. So the "ACPI Shutdown" Wiki page tells you to add
>> this to the sudoers config:
>>
>> %mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh
>>
>
> I have this in the sudoers file, with the addition of
> /usr/bin/checklogin.sh
>
>>
>> as that has the "NOPASSWD:" option.
>>
>
> I also just noticed some bad pathways in setup, /usr/local/bin where it
> should have been /usr/bin and visa-versa, maybe it will turn off tonight,
> thanks all!
>
Re: ACPI [ In reply to ]
On Sat, 12 Sep 2020 16:38:11 -0400, you wrote:

>Still no joy. When I ran "sudo visudo" the comments said "consider creating
>a sudoers.d file" (or something similar) which I didn't because the wiki
>saed add this to the end of the file. Should I try the former?

visudo will only edit the /etc/sudoers file. It is usually better
just to create a new file under /etc/sudoers.d, as the /etc/sudoers
file can be updated by package updates. However, visudo does do basic
sanity checks on your edits, which does not happen if you create a new
/etc/sudoers.d file. For a /etc/sudoers.d file to work, it needs to
be owned by root and you need to remove all write privileges. It is
also important that any executable file or script you are listing in
the sudoers.d file is also not writeable at all (or only writeable by
root). So when I created my /usr/local/bin/mythtv-systemctl-helper.sh
script, I did this:

sudo chown root:mythtv /usr/local/bin/mythtv-systemctl-helper.sh
sudo chmod u=rx,g=rx /usr/local/bin/mythtv-systemctl-helper.sh

Then I created a /etc/sudoers.d/mythtv-systemctl-helper file
containing this:

mythtv,%mythtv ALL=NOPASSWD:/usr/local/bin/mythtv-systemctl-helper.sh

which says that the mythtv user or any user in the mythtv group
(%mythtv) can run the mythtv-systemctl-helper.sh file with sudo
without needing a password. I did this:

sudo chown root:root /etc/sudoers.d/mythtv-systemctl-helper
sudo chmod u=r,g=r /etc/sudoers.d/mythtv-systemctl-helper

to secure that file and make sudo accept it as valid.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: ACPI [ In reply to ]
On 9/12/20 3:38 PM, Daryl McDonald wrote:
> Still no joy. When I ran "sudo visudo" the comments said "consider creating
> a sudoers.d file" (or something similar) which I didn't because the wiki
> saed add this to the end of the file. Should I try the former?

Use: man visudo to see the options. You're looking for the --file switch
and could enter a path like /etc/sudoers.d/mythtv

Personal note, if you're touching anything related to sudoers[.d/*], then
open at least one other terminal window and type: sudo -i in it. That way
you can recover from errors you make (I made) when editing, although my
1st attempt was without visudo. Test from another window with: sudo -k
and then sudo -i. You don't want to disable the sudo command, even though
it's possible to recover from it.

--
Bill
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: ACPI [ In reply to ]
I hope this result will confirm that I have followed your instruction:

daryl@trieli:~$ ls -al /etc/sudoers.d/acpi
-r--r----- 1 root root 162 Sep 13 09:45 /etc/sudoers.d/acpi
daryl@trieli:~$ sudo cat /etc/sudoers.d/acpi
#instead of adding directly to sudoers file, this file was created

#mythtv,%mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh,
/usr/bin/checklogin.sh

daryl@trieli:~$ ls -al /sbin/shutdown
lrwxrwxrwx 1 root root 14 Jul 6 17:38 /sbin/shutdown -> /bin/systemctl
daryl@trieli:~$ ls -al /usr/bin/setwakeup.sh
-r-xr-xr-x 1 root mythtv 1221 Sep 10 16:37 /usr/bin/setwakeup.sh
daryl@trieli:~$ ls -al /usr/bin/checklogin.sh
-r-xr-xr-x 1 root mythtv 1222 Sep 10 16:47 /usr/bin/checklogin.sh
daryl@trieli:~$ cat /usr/bin/setwakeup.sh
#!/bin/bash
#$1 is the first argument to the script. It is the time in seconds since
1970
#this is defined in mythtv-setup with the time_t argument

echo 0 > /sys/class/rtc/rtc0/wakealarm #this clears your alarm.
echo $1 > /sys/class/rtc/rtc0/wakealarm #this writes your alarm

LOG_FILE='/var/log/mythtv/hwclock-rebootTime.log' #log file

# Now write the time the system is expected to come out of power save mode
# so there is at least a small record of when if it was supposed to recover

# Note:- Log file will just keep growing

# date in Epoch format
a="`date +%s`"

# Subtract Current time from Future time
let "b=$1-$a"

# echo $b
# echo "result of time subtraction `date -d @$b`"

# Get Date and Subtract 1,.. as date starts from 1st Jan 1970
dte=`date -d @$b +%d`
let "dte -= 1"

echo "Current Time ->`date`" >> $LOG_FILE

# Simple check to determine if to include days in output string
if (dte=0)
then
echo "Shutting down for ->`date -d @$b +%Hhrs:%MMins`" >> $LOG_FILE
else
echo "Shutting down for ->$[dte]Days `date -d @$b +%Hhrs:%MMins`" >>
$LOG_FILE
fi

echo "Wake up at approx.->`date -d @$1`" >> $LOG_FILE
echo "------------------------------------------------------" >> $LOG_FILE

daryl@trieli:~$ cat /usr/bin/checklogin.sh
#!/bin/bash
# Check to see if anyone is currently logged in or if the machine was
recently switched on.
# Echoed text appears in log file. It can be removed and --quiet added to
the
# grep command once you are satisfied that mythTV is working properly.
# Exit codes:-
# 2 - Machine recently switched on, don't shut down.
# 1 - A user is logged in, don't shut down.
# 0 - No user logged in, OK to shut down.

# Customizable variables
MIN_UPTIME=10 # Minimum up time in minutes
# End of customizable variables

# Get a date/time stamp to add to log output
DATE=`date +%F\ %T\.%N`
DATE=${DATE:0:23}

UPTIME=`cat /proc/uptime | awk '{print int($1/60)}'`

if [ "$UPTIME" -lt "$MIN_UPTIME" ]; then
echo $DATE Machine uptime less than $MIN_UPTIME minutes, don\'t shut
down.
exit 2
fi

# Some configurations ( at least lxdm + xfce4) do not report GUI-logged-on
users
# with "who" or "users".
# pgrep tests if processes named xfce* exist

XFCE_PROCS=`pgrep xfce`

USERS=`who -q | tail -n 1 | sed 's/[a-z #]*=//'`

if [ "$USERS" == "0" ] && [ "$XFCE_PROCS" == "" ]; then
echo $DATE No users are logged in, ok to shut down.
exit 0
else
echo $DATE Someone is still logged in, don\'t shut down.
exit 1
fi

daryl@trieli:~$

On Sun, Sep 13, 2020 at 1:42 AM Stephen Worthington <
stephen_agent@jsw.gen.nz> wrote:

> On Sat, 12 Sep 2020 16:38:11 -0400, you wrote:
>
> >Still no joy. When I ran "sudo visudo" the comments said "consider
> creating
> >a sudoers.d file" (or something similar) which I didn't because the wiki
> >saed add this to the end of the file. Should I try the former?
>
> visudo will only edit the /etc/sudoers file. It is usually better
> just to create a new file under /etc/sudoers.d, as the /etc/sudoers
> file can be updated by package updates. However, visudo does do basic
> sanity checks on your edits, which does not happen if you create a new
> /etc/sudoers.d file. For a /etc/sudoers.d file to work, it needs to
> be owned by root and you need to remove all write privileges. It is
> also important that any executable file or script you are listing in
> the sudoers.d file is also not writeable at all (or only writeable by
> root). So when I created my /usr/local/bin/mythtv-systemctl-helper.sh
> script, I did this:
>
> sudo chown root:mythtv /usr/local/bin/mythtv-systemctl-helper.sh
> sudo chmod u=rx,g=rx /usr/local/bin/mythtv-systemctl-helper.sh
>
> Then I created a /etc/sudoers.d/mythtv-systemctl-helper file
> containing this:
>
> mythtv,%mythtv ALL=NOPASSWD:/usr/local/bin/mythtv-systemctl-helper.sh
>
> which says that the mythtv user or any user in the mythtv group
> (%mythtv) can run the mythtv-systemctl-helper.sh file with sudo
> without needing a password. I did this:
>
> sudo chown root:root /etc/sudoers.d/mythtv-systemctl-helper
> sudo chmod u=r,g=r /etc/sudoers.d/mythtv-systemctl-helper
>
> to secure that file and make sudo accept it as valid.
> _______________________________________________
> mythtv-users mailing list
> mythtv-users@mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org
>
Re: ACPI [ In reply to ]
On Sun, Sep 13, 2020 at 9:26 AM Bill Meek <keemllib@gmail.com> wrote:

> On 9/12/20 3:38 PM, Daryl McDonald wrote:
> > Still no joy. When I ran "sudo visudo" the comments said "consider
> creating
> > a sudoers.d file" (or something similar) which I didn't because the wiki
> > saed add this to the end of the file. Should I try the former?
>
> Use: man visudo to see the options. You're looking for the --file switch
> and could enter a path like /etc/sudoers.d/mythtv
>
> Personal note, if you're touching anything related to sudoers[.d/*], then
> open at least one other terminal window and type: sudo -i in it. That way
> you can recover from errors you make (I made) when editing, although my
> 1st attempt was without visudo. Test from another window with: sudo -k
> and then sudo -i. You don't want to disable the sudo command, even though
> it's possible to recover from it.
>
> --
> Bill
>
> Sorry Bill, I'm not getting this at all. But I think I received
"beginner's luck" in this process. I tried to comment out the original
addition to the sudoers file, while creating the sudoers.d/acpi file in a
separate terminal. The "sanity check" kicked in with an error on line 30 of
the sudoers file (so I removed all together my previous addition) and then
was asked what I wanted to do with the new sudoers.d/acpi file, so I
commented it out too.

So I guess now I'm asking if what I've done is functional (if I uncomment
the line in /etc/sudoers.d/acpi) or do I need further education?
Re: ACPI [ In reply to ]
On Sun, 13 Sep 2020 08:25:46 -0500, you wrote:

>Personal note, if you're touching anything related to sudoers[.d/*], then
>open at least one other terminal window and type: sudo -i in it. That way
>you can recover from errors you make (I made) when editing, although my
>1st attempt was without visudo. Test from another window with: sudo -k
>and then sudo -i. You don't want to disable the sudo command, even though
>it's possible to recover from it.

That is excellent advice. I forgot about that problem of sudo being
disabled by an sudoers file with bad syntax in it. That is not a
problem to me as one of the first things I ever do with an Ubuntu
install is to add a password to the root account so that I can login
directly as root:

sudo passwd

I also set up SSH as allowing root logins.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: ACPI [ In reply to ]
On Sun, 13 Sep 2020 13:39:36 -0400, you wrote:

>I hope this result will confirm that I have followed your instruction:
>
>daryl@trieli:~$ ls -al /etc/sudoers.d/acpi
>-r--r----- 1 root root 162 Sep 13 09:45 /etc/sudoers.d/acpi

Yes, that is good.

>daryl@trieli:~$ sudo cat /etc/sudoers.d/acpi
>#instead of adding directly to sudoers file, this file was created
>
>#mythtv,%mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh, /usr/bin/checklogin.sh

Presuming that extra spaces are fine, that should work once the line
above is uncommented by removing the #. The only required space in
that line is the one between %mythtv and ALL. The others are just for
readability and I have not put them in my sudoers line.

>daryl@trieli:~$ ls -al /sbin/shutdown
>lrwxrwxrwx 1 root root 14 Jul 6 17:38 /sbin/shutdown -> /bin/systemctl
>daryl@trieli:~$ ls -al /usr/bin/setwakeup.sh
>-r-xr-xr-x 1 root mythtv 1221 Sep 10 16:37 /usr/bin/setwakeup.sh

The permissions are allowing this file to be executed by anyone
(o=rx). It should have o=r. So "sudo chmod o=r
/usr/bin/setwakeup.sh". I also prefer to never put things in system
directories like /usr/bin if I can help it, so I would put the
setwakeup.sh file in /usr/local/bin and change the acpi file to point
to that location.

>daryl@trieli:~$ ls -al /usr/bin/checklogin.sh
>-r-xr-xr-x 1 root mythtv 1222 Sep 10 16:47 /usr/bin/checklogin.sh

Again, it has o=rx allowing any user to run it. It needs to be o=r,
so only mythtv group users or root can run it.

I have not checked the contents posted for the setwakeup.sh and
checklogin.sh files as I have never used them. I presume that they
are just copied from the Wiki page and therefore should work, but as I
understand it, it does depend on your BIOS. Some BIOSes are buggy and
to not do timer wakeups properly.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: ACPI [ In reply to ]
>
>
> understand it, it does depend on your BIOS. Some BIOSes are buggy and
>
> to not do timer wakeups properly.
>

That‘s my experience too. You have to check the BIOS settings and do some
experiments. Once properly configured it runs fine.

Maybe there is a hint that may help: In my setwakeup.sh script the
following line is called (but I can‘t remember the purpose):

hwclock --rtc=/dev/rtc0 --systohc --utc --noadjfile

You can find the whole script here:
https://github.com/jims-code/MythTV-Helpers/tree/master/ACPI-wakeup

Kind Regards
Jens



>