Problems with the scripts for kill and start XBMC
#1
I've followed the guide:
http://forum.xbmc.org/showthread.php?tid=30230

Got two scripts that, 1. start xbmc and 2. kill xbmc.

The problem is that sometimes, if Ive have started xbmc with the script, I cant kill xbmc with the script.

Im running Ubuntu 8.10 and latest SVN xbmc.

Have someone looked in to this scripts lately?

BTW, I also for a couple of month ago followed some guide, to be able to start up my htpc after a suspend, with the remote.

Suddenly that didnt work anylonger.
Have someone maybe done the same thing as I, and know if something has changed in Ubuntu, disable this function?

EDIT: The last thing about wake up, I think I can fix that.
http://www.mythtv.org/wiki/MCE_Remote

Code:
In order for the button to wake, you need to specify the USB hub in /proc/acpi/wakeup. If you cat /proc/acpi/wakeup, you should see something like this:

Device  S-state   Status   Sysfs node
HUB0      S5     disabled  pci:0000:00:08.0
HUB1      S4     disabled
USB0      S3     disabled  pci:0000:00:02.0
USB1      S3     disabled  pci:0000:00:02.1

If you issue the following command, the disable status will toggle to enabled

sudo sh -c 'echo "USB0" > /proc/acpi/wakeup'

Should result in:

Device  S-state   Status   Sysfs node
HUB0      S5     disabled  pci:0000:00:08.0
HUB1      S4     disabled
USB0      S3     enabled   pci:0000:00:02.0
USB1      S3     disabled  pci:0000:00:02.1

This command can be saved in your local.start

It also might be useful to change the MythTV exit settings to issue hibernate-ram on shutdown

This is the file I edited the first time, but it was now disabled...

/Söder
Reply
#2
I take a different approach than the thread you mentioned and I haven't run into too much trouble.

I launch irexec through /etc/rc.local by adding the line below (change to match the username you use to run xbmc):

Code:
su -c '/usr/bin/irexec -d /home/killerbeesateme/.lircrc' -l killerbeesateme

And then I use 1 script to start and stop xbmc. I combined several mythtv scripts I've found and it's worked wonders for me. Very rarely does XBMC freeze to a point where I have to kill -9 it.

I use a lock file to prevent multiple instances of the script to run within 10 seconds of each other. I also put "/usr/bin/iecset audio on" in there to make sure my optical sound is working, so if you don't use optical, I would remove it.

Code:
#!/bin/sh
#xbmc_harmony.sh
#Start xbmc by remote button press from irexec

LOCK="/tmp/${0##*/}.lock"
[ -e "${LOCK}" ] && exit 0
touch "${LOCK}"
if [ ! "$(pidof xbmc.bin)" ]
then
        /usr/bin/iecset audio on > /dev/null
        DISPLAY=:0 xbmc & > /dev/null
        sleep 10
        rm "${LOCK}"
else
        killall xbmc.bin
        sleep 10
        rm "${LOCK}"
fi
Reply
#3
killerbeesateme Wrote:I take a different approach than the thread you mentioned and I haven't run into too much trouble.

I launch irexec through /etc/rc.local by adding the line below (change to match the username you use to run xbmc):

Code:
su -c '/usr/bin/irexec -d /home/killerbeesateme/.lircrc' -l killerbeesateme

And then I use 1 script to start and stop xbmc. I combined several mythtv scripts I've found and it's worked wonders for me. Very rarely does XBMC freeze to a point where I have to kill -9 it.

I use a lock file to prevent multiple instances of the script to run within 10 seconds of each other. I also put "/usr/bin/iecset audio on" in there to make sure my optical sound is working, so if you don't use optical, I would remove it.

Code:
#!/bin/sh
#xbmc_harmony.sh
#Start xbmc by remote button press from irexec

LOCK="/tmp/${0##*/}.lock"
[ -e "${LOCK}" ] && exit 0
touch "${LOCK}"
if [ ! "$(pidof xbmc.bin)" ]
then
        /usr/bin/iecset audio on > /dev/null
        DISPLAY=:0 xbmc & > /dev/null
        sleep 10
        rm "${LOCK}"
else
        killall xbmc.bin
        sleep 10
        rm "${LOCK}"
fi

I dont really understand? Does this script work both for start xbmc and kill it?

So if xbmc NOT running, it start it, and if its running, it kills it?
If so thats cool. But is it "really" killing it? Cause sometimes xbmc hangs, and taking like 100 % cpu, and then I want it to be really reallu hard killed....

EDIT: I now tried it, and it killed xbmc.
I then tried to run it again, and it started XBMC, but also left this in the terminal...

"htpc@htpc-desktop:~/scripts$ sh startkillxbmc.sh
The XBMC_HOME environment variable is not set.
htpc@htpc-desktop:~/scripts$ CRITSEC[0x8bec684]: Trying to enter destroyed section.
CRITSEC[0x8bec684]: Trying to leave destroyed section.
CRITSEC[0x8bee1c0]: Trying to enter destroyed section.
CRITSEC[0x8bee1c0]: Trying to leave destroyed section."

and it was never finnished.....just kept flashing..

Can this be the reason I couldnt run both my scripts in the same "session"...
If I used one script to start...it never ended...and then I could use next script to kill? ... and if killed...then I could not use the other script to start...

EDIT2: Ive not tried to use my scripts....and its when Ive used my startXBMC.sh I no longer can use my killXBMC.sh. And not the one you gave me eather.....so I guess thats something wrong with it..

First after I killed xmbc the normal way, your script start xbmc since Ive already pressed that buttom trying to use it for a kill. =)

But your script works....only irexec is runnig.. =)

But can someone say whats wrong with the scripts I used for startxbmc?


/Söder
Reply
#4
Sorry, I didn't even think to check back if you had questions until just now.

As far as the "Trying to leave destroyed section" and "Home Environment Variable" not set errors, manually running xbmc gave me the same errors. I think this is just part of the SVN. I actually did get the "Trying to leave destroyed section" error on stable if I'm remembering correctly. The way I'm killing xbmc in the script is the same as choosing shutdown from the menu.

As far as the original startup script in the thread you linked, I think I know the culprit. I believe you have to edit it to add the "DISPLAY=:0" before calling xbmc so it outputs to the correct display. If you're running multiple X servers, you can change the 0 to whatever X server is the correct one for the TV. The only surefire way to check is to run the script and then use "pgrep xbmc.bin" right away and see if it spits out a PID. That'll tell you if it's launching but then killing itself because it can't find a display.

I just edited the script to take into account xbmc being frozen. I don't have a way of testing this, as I don't have a solid way of making xbmc stuck in my setup. Give it a shot, it may work for you. I've been setting the sleep time at 10 seconds for the script but you can probably reduce that. I'm just cautious.

Code:
#!/bin/sh
#xbmc_harmony.sh
#Start xbmc by remote button press from irexec

LOCK="/tmp/${0##*/}.lock"
[ -e "${LOCK}" ] && exit 0
touch "${LOCK}"
if [ ! "$(pidof xbmc.bin)" ]
then
        /usr/bin/iecset audio on > /dev/null
        DISPLAY=:0 xbmc & > /dev/null
        sleep 10
        rm "${LOCK}"
else
        killall xbmc.bin
        sleep 10
        if [ ! "$(pidof xbmc.bin)" ]
        then
                PID=`pidof xbmc.bin`
                kill -9 $PID
                sleep 10
                rm "${LOCK}"
        else
                rm "${LOCK}"
        fi
fi
Reply
#5
killerbeesateme Wrote:Sorry, I didn't even think to check back if you had questions until just now.

As far as the "Trying to leave destroyed section" and "Home Environment Variable" not set errors, manually running xbmc gave me the same errors. I think this is just part of the SVN. I actually did get the "Trying to leave destroyed section" error on stable if I'm remembering correctly. The way I'm killing xbmc in the script is the same as choosing shutdown from the menu.

As far as the original startup script in the thread you linked, I think I know the culprit. I believe you have to edit it to add the "DISPLAY=:0" before calling xbmc so it outputs to the correct display. If you're running multiple X servers, you can change the 0 to whatever X server is the correct one for the TV. The only surefire way to check is to run the script and then use "pgrep xbmc.bin" right away and see if it spits out a PID. That'll tell you if it's launching but then killing itself because it can't find a display.

I just edited the script to take into account xbmc being frozen. I don't have a way of testing this, as I don't have a solid way of making xbmc stuck in my setup. Give it a shot, it may work for you. I've been setting the sleep time at 10 seconds for the script but you can probably reduce that. I'm just cautious.

Code:
#!/bin/sh
#xbmc_harmony.sh
#Start xbmc by remote button press from irexec

LOCK="/tmp/${0##*/}.lock"
[ -e "${LOCK}" ] && exit 0
touch "${LOCK}"
if [ ! "$(pidof xbmc.bin)" ]
then
        /usr/bin/iecset audio on > /dev/null
        DISPLAY=:0 xbmc & > /dev/null
        sleep 10
        rm "${LOCK}"
else
        killall xbmc.bin
        sleep 10
        if [ ! "$(pidof xbmc.bin)" ]
        then
                PID=`pidof xbmc.bin`
                kill -9 $PID
                sleep 10
                rm "${LOCK}"
        else
                rm "${LOCK}"
        fi
fi

Ok, thanks. I now use the script you gave me yesterday, to start XBMC. I still have a button linked to the kill script I used.

But lets see if I understand your right...
You have now edited YOUR script, to "hard kill" my XBMC if not responding to the normal shutdown? Is the normal shutdown still there, or is it a hard kill everytime I run your script, and xbmc are running?

/Söder
Reply
#6
It does a normal shutdown, waits 10 seconds to see if xbmc is shutdown. If it hasn't ended nicely, it should forcibly kill it.

I can't vouch for it working 100%, as I don't have a way to test it, but if a normal shutdown fails, it should kill it.

For posterity:

If for some reason the script gets interrupted or it doesn't function correctly, it could leave the lock file. So if you suddenly notice it stop working to either kill or start xbmc, check your /tmp directory for a file that ends in .lock and delete it. The script should then function normally or indicate that it's not working properly.
Reply
#7
killerbeesateme Wrote:It does a normal shutdown, waits 10 seconds to see if xbmc is shutdown. If it hasn't ended nicely, it should forcibly kill it.

I can't vouch for it working 100%, as I don't have a way to test it, but if a normal shutdown fails, it should kill it.

For posterity:

If for some reason the script gets interrupted or it doesn't function correctly, it could leave the lock file. So if you suddenly notice it stop working to either kill or start xbmc, check your /tmp directory for a file that ends in .lock and delete it. The script should then function normally or indicate that it's not working properly.

So far, it works good. Ive kept my other kill script also, if your should not work.

But I got one more question. I normaly let XBMC to put the HTPC in suspend with my normal power button. That option in XBMC is set to "suspend".

But will your script do the same then? Or is first an normal soft kill the script tries to do, and then a hard?

/Söder
Vero 4K with unRAID server and mysql (mariadb)
Reply
#8
soder Wrote:So far, it works good. Ive kept my other kill script also, if your should not work.

But I got one more question. I normaly let XBMC to put the HTPC in suspend with my normal power button. That option in XBMC is set to "suspend".

But will your script do the same then? Or is first an normal soft kill the script tries to do, and then a hard?

/Söder

OK, now Ive tested your script, and it works good so far. It kills my xbmc and start it. Never a problem. Only when I sometimes press to many times, and kill with my oter script. Then the second use of your script start or kill xbmc when it should.

Buts thats only happends when I try around start/kill very often.

BUT, another question. My "suspend script" isnt working very well. Is this something you can help me with?

#!/bin/sh
sudo /etc/acpi/sleep.sh force

/Söder
Vero 4K with unRAID server and mysql (mariadb)
Reply
#9
I haven't played with suspend. I just turn the PC on and off as I have a fairly set schedule.

Have you tried running "sudo pm-suspend" instead? I just tested it on my system and it brought it right down in about a second.
Reply
#10
killerbeesateme Wrote:I haven't played with suspend. I just turn the PC on and off as I have a fairly set schedule.

Have you tried running "sudo pm-suspend" instead? I just tested it on my system and it brought it right down in about a second.

You mean:
#!/bin/sh
sudo pm-suspend

in a script?

I will try.

And one more thing. Your script for start/kill XBMC works nice for me, but when I tried to help my friend with the same thing, it didnt work. I know IRexec is running, cause my other kill script worked, but your didnt start, or kill xbmc.

We're both using the SVN, and his XBMC also start with the command "xbmc" in terminal.

/Söder
Vero 4K with unRAID server and mysql (mariadb)
Reply
#11
It should be universal. The only things I could think of is that he can't write the lock file, the display is no 0, or xbmc is not in his path.

If you run the script manually, what if any errors show up?
Reply
#12
Hi!

I am working on my first linux HTPC. I did not know linux when I started, but know other computer stuff and have been able to figure most things out. I am running ubuntu 8.04 with pre-compiled xbmc.

I am struggling with user access. I have created a shutdown script (using sudo /sbin/shutdown) and I have edited sudoer to allow this to run without pwd question. This worksfine

I am autostarting the irexec using the SESSIONS graphical tool as described in:
http://forum.xbmc.org/showthread.php?tid=30230

No good, then the shutdown does not work. If I start it manually with sudo irexec -d it works.

I cannot find a lot of information about this in any forum, is it common practise to enable root and/or give more than default access to the user running XBMC?

I see that yoy are using su:
Quote:su -c '/usr/bin/irexec -d /home/killerbeesateme/.lircrc' -l killerbeesateme

If thats the recommended method I am fine with that, but I am bit surprised.

I have also tried using the PolicyKit.conf to give more access, but I can see no effect.

I am also trying to call up the fast-user-switch-applet by sending ctrl-alt-Delete with irxevent. No luck. I first tried to start the switch from the terminal, but it is not possible or is it?

/thanks
Reply
#13
I tested to enable root and use su -c.
Yes, understand now this is more or less same as sudo. It also ask for pwd.

What am I missing? I guess I can get it to work by allow irexec etc in sudoer?
Reply
#14
killerbeesateme Wrote:I haven't played with suspend. I just turn the PC on and off as I have a fairly set schedule.

Have you tried running "sudo pm-suspend" instead? I just tested it on my system and it brought it right down in about a second.

Hi again. You scripts still works like a charm. =)

I got a new question: Is it possible to do a script that "ctrl+alt+back space" ?

Sometimes I need to do that, and then in 10 sec in will automaticly log in again, and I can later start it with your script.

Is it possble to make a script for that, instead of use the keyboard?

/Söder
Vero 4K with unRAID server and mysql (mariadb)
Reply

Logout Mark Read Team Forum Stats Members Help
Problems with the scripts for kill and start XBMC0