PDA

View Full Version : 11.04 auto shutdown problem



sqeelurgle
October 2nd, 2011, 10:06 AM
I am having a problem with the auto shutdown when idle using mythwelcome. I have set it up exactly as I have in the past, and using the instructions on the mythtv wiki. It just will not work. The backend log contains multiple errors saying "sudo no tty present and no askpass program specified" when it tries to call /usr/bin/setwakeup.sh. I have multiple checked that /usr/bin/setwakeup.sh is in the sudoers file under %mythtv ALL NOPASSWD: /usr/bin/setwakeup.sh It doesn't seem to be working though. Has anyone else had trouble with this? Has anyone fixed it?

Thanks

nickrout
October 3rd, 2011, 05:27 AM
%mythtv ALL NOPASSWD: /usr/bin/setwakeup.sh should that be
%mythtv ALL=(ALL) NOPASSWD: /usr/bin/setwakeup.sh

sqeelurgle
October 3rd, 2011, 09:47 AM
I have tried both those variants, but I'll try it again.

sqeelurgle
October 3rd, 2011, 12:34 PM
OK, I looked at it, and tried both variants. Didn't work. I also should mention that the line in question is the last line in the sudoers file, because I know that order makes a difference.

I tried


sudo -u mythtv sudo -l

and it said that the mythtv user has the right to run (ALL) NOPASSWD /usr/bin/setwakeup.sh. The backend log is still showing errors though, and if I try it from the terminal it still asks for a password.

thatguruguy
October 3rd, 2011, 01:55 PM
OK, I looked at it, and tried both variants. Didn't work. I also should mention that the line in question is the last line in the sudoers file, because I know that order makes a difference.

I tried


sudo -u mythtv sudo -land it said that the mythtv user has the right to run (ALL) NOPASSWD /usr/bin/setwakeup.sh. The backend log is still showing errors though, and if I try it from the terminal it still asks for a password.

A couple thoughts..

First, you're not mythtv, so it would still ask for a password from you, I think. You may be able to get around that by having your sudoers file set up like this:

%admin ALL=(ALL) NOPASSWD:/whatever/is/being/run

Secondly, you may be going about this somewhat backwards. Do the scripts themselves have sudo calls in them? If so, those calls need to be in your sudoers file, not the scripts. For example, I have both huludesktop and XBMC installed on my Mythtv box. Huludesktop wants a particular format for my /etc/lirc/hardware.conf file which includes the following line:

REMOTE_LIRCD_ARGS="-r"... but that line causes double key presses in XBMC. To deal with that problem, I created a "default" hardware.conf file (called hardware.default) with the line REMOTE_LIRCD_ARGS="" and a "released" hardware.conf file (called hardware.released, naturally) with the line REMOTE_LIRCD_ARGS="-r", and I created a startup script for huludesktop which copies the "released" file to hardware.conf prior to launching huludesktop, and then copies the "default" file to hardware.conf after huludesktop exits. The script is named "hulu_start" and looks like this:

#!/bin/sh
sudo /bin/cp /etc/lirc/hardware.released /etc/lirc/hardware.conf && sudo /etc/init.d/lirc restart
huludesktop
sudo /bin/cp /etc/lirc/hardware.default /etc/lirc/hardware.conf && sudo /etc/init.d/lirc restart
irexec -dIn my sudoers file, it doesn't matter if I allow execution of the "hulu_start" file without a password. What matters is that the sudo calls within the script are executed without a password. The relevant part of my sudoers file looks like this:

%admin ALL=(ALL)NOPASSWD:/bin/cp * /etc/lirc/hardware.conf
%admin ALL=(ALL)NOPASSWD:/etc/init.d/lirc restart

sqeelurgle
October 3rd, 2011, 10:35 PM
What my mythtv box is set up to do is boot automatically 10 minutes before a recording, and when it is idle, then run a script (/usr/bin/setwakeup.sh)to set the time for the next wakeup, and then shutdown. It has to be able to run that script without a password or it won't work. Mythtv is the user that the backend runs on, so that user has to be able to run that script. I do have an identical sudoers line that allows my user log in access to the same scripts without a password just to test it though. If I add the NOPASSWD option in to %admin, would mythtv then be able to run it? I guess what I am asking is can mythtv (the user) be a member of the admin group? And is that wise?

Thanks

thatguruguy
October 3rd, 2011, 11:59 PM
What my mythtv box is set up to do is boot automatically 10 minutes before a recording, and when it is idle, then run a script (/usr/bin/setwakeup.sh)to set the time for the next wakeup, and then shutdown. It has to be able to run that script without a password or it won't work. Mythtv is the user that the backend runs on, so that user has to be able to run that script. I do have an identical sudoers line that allows my user log in access to the same scripts without a password just to test it though. If I add the NOPASSWD option in to %admin, would mythtv then be able to run it? I guess what I am asking is can mythtv (the user) be a member of the admin group? And is that wise?

Thanks

The first point I was making was that you can't run the script with no password, unless you are authorized to do so in the sudoers file.

The second point I was making is that the wakeup.sh (or whatever it's called) doesn't need to be in the sudoers file; the calls made in wakeup.sh need to be in the sudoers file. You haven't posted the actual scripts yet, because you presumably want us all to guess what's in them. But assume, for a moment, that you have a script that's called "shutdown_now.sh" that's called by mythtv, and is stored as /usr/local/bin/shutdown_now.sh. The script is as follows:

#!/bin/sh
sudo shutdown -H now

In your sudoers file, you don't need:
[CODE] %mythtv ALL=(ALL)NOPASSWD:/usr/local/bin/shutdown_now.shYou need:

%mythtv ALL=(ALL)NOPASSWD:/sbin/shutdown

nickrout
October 4th, 2011, 12:13 AM
What my mythtv box is set up to do is boot automatically 10 minutes before a recording, and when it is idle, then run a script (/usr/bin/setwakeup.sh)to set the time for the next wakeup, and then shutdown. It has to be able to run that script without a password or it won't work. Mythtv is the user that the backend runs on, so that user has to be able to run that script. I do have an identical sudoers line that allows my user log in access to the same scripts without a password just to test it though. If I add the NOPASSWD option in to %admin, would mythtv then be able to run it? I guess what I am asking is can mythtv (the user) be a member of the admin group? And is that wise?

Thanks

Are you 100% sure it is the backend that runs the script? mythbuntu runs the backend as user mythtv and the frontend as the user you first setup on installation.

I would not set %admin (ie the admin group) as NOPASSWD for everything, it is too insecure.

If you want to try commands as a particular user, become that user and then try the command, eg
su - mythtv
/usr/bin/setwakeup.sh

(If you don't know mythtv user's password then use
sudo su - mythtv

And don't forget in sudoers %mythtv does not mean the USER mythtv, it means memebers of the GROUP mythtv. You can see what groups a user is in by running
id username.

sqeelurgle
October 4th, 2011, 11:41 AM
OK, I have finally managed to get the mythtv box on the net, so Ican cut and paste a few things.

Here is the full sudoers file as it currently exists:


#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Defaults visiblepw
# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL

#includedir /etc/sudoers.d
%mythtv ALL=(ALL) NOPASSWD:/sbin/shutdown, /usr/bin/setwakeup.sh, /usr/bin/mythshutdown
peter ALL=(ALL) NOPASSWD:/sbin/shutdown, /usr/bin/setwakeup.sh, /usr/bin/mythshutdown

I have tried with and without the % in front of mythtv. I have tried with ALL=(ALL) NOPASSWD and with ALL = NOPASSWD

The script /usr/bin/setwakeup.sh is here:


#!/bin/sh
#
# set ACPI Wakeup time
# usage: setwakeup.sh seconds
# seconds - number of seconds from epoch to UTC time (time_t time format)
#
# set UTCBIOS to true if bios is using UTC time
# set UTCBIOS to false if bios is using local time

UTCBIOS=false

if $UTCBIOS
then
#utc bios - use supplied seconds
SECS=$1
else
#non utc bios - convert supplied seconds to seconds from
#epoch to local time
SECS=`date -u --date "\`date --date @$1 +%F" "%T\`" +%s`
fi

echo 0 > /sys/class/rtc/rtc0/wakealarm # clear alarm
echo $SECS > /sys/class/rtc/rtc0/wakealarm # write the waketime

I didn't write the script - it is from the mythtv wiki and I have used it before. This whole process I have used before, and have no idea why it isn't working this time. Basically, when the backend is idle, it will call this script to write a wakeup time to the BIOS, and will the shut down. The BIOS then wakes the machine for the next recording. Currently there are a whole string of errors in the backend log that say:


2011-10-01 14:27:56.133 I'm idle now... shutdown will occur in 120 seconds.
2011-10-01 14:29:55.227 Running the command to set the next scheduled wakeup time :-
sudo sh -c "/usr/bin/setwakeup.sh 1317457440"
sudo: no tty present and no askpass program specified
2011-10-01 14:29:55.562 SetWakeuptimeCommand failed, shutdown aborted


Can anyone see why it isn't working?

alien878
October 4th, 2011, 02:11 PM
My entry (which is working) is:


mythtv ALL= NOPASSWD: /myth/bin/mythwelcome-set-alarm.sh, /sbin/reboot, /sbin/poweroff

I believe your first try was missing the "= ". I've never used "ALL=(ALL) NOPASSWD:".

Note: replace the command(s) with the ones appropriate to your setup.

Cheers,

Allen

Neon Dusk
October 4th, 2011, 10:36 PM
OK, I have finally managed to get the mythtv box on the net, so Ican cut and paste a few things.

The script /usr/bin/setwakeup.sh is here:

...

I didn't write the script - it is from the mythtv wiki and I have used it before.

I made a change to that part of the wiki a few weeks back (to remove the need to have sh in the sudoers file).

All you should need to do is change the script call (in MythShutdown/MythWelcome Settings) from 'sudo sh -c "/usr/bin/setwakeup.sh $time"' to 'sudo /usr/bin/setwakeup.sh $time'

sqeelurgle
October 6th, 2011, 11:43 AM
OK, I seem to have got this. I did 3 things, so I'm not sure which was the important one (or if all 3 were needed.

1. I put my sudoers file to the same pattern as alien. I think that's what it was originally - I had a direct cut and paste from the mythtv wiki on ACPI.

2. I changed the backend setting to the one suggested by Neon Dusk.

3. I edited the database. I had a mythtv setup but it started going bad, so I backed up database and recordings and installed from scratch. What I didn't realise was the the hostname for the different machines was different, so when I reinstalled the backup up database, I ended up with settings for both host names in the database. That came to light when I tried to scan for changes to the video directory. Anyway, I edited the database, and so far have taken out most of the references to the old host name.

The system now auto-shuts down.

Thank you all for your help.

shubhampatni86
March 16th, 2012, 01:00 PM
Hi, I am using Ubuntu 11.10 64 bit on my Vostro 3350 i7-4 core system.
I am facing some wired problem here :
1) when system boot some time system show me blank screen with back sight light, so I need to restart it 2-3 times again then it work for me with option press S to skip , M for manuel , C for continue like.

2) System got shutdown as the load started to increase, I am facing these problem from long times.


any one have solution for this.


thanks