Linux HOW-TO make XBMC for Linux auto start on Ubuntu
#19
Chaos_666 Wrote:Hi there
Great Howto, thats exactly how i solved this problem, before there was this howto.

But what happens if you press the Off Button on the remote or shuts it down via menu?
Here it quits xbmc but stays in X?!

Anyone knows a solution for that?

THX
Chaos

I am going to explain this by an indepth example as it will help people understand what is occuring.

What we are going to achieve is xbmc will "restart" when it quits, and the X session will stay running.

In the excellent HOWTO provided in this thread, you find that the .xinitrc file will be executed when Xorg (via startx) begins.

Code:
#!/bin/bash
exec /usr/bin/xbmc --standalone

.. and when xbmc "quits", your xsession quits and you are dropped back to the console.

This occurs because startx "runs" the .xinitrc and when that "process" or the spawned controlling process finishes, startx finishes also.

So the idea is that we will keep the "process" running, so that startx never quits back to the console.

So to show the "chain of events"
Code:
mingetty
  --> logs in
        --> bash executes
             --> .bashrc runs
                   startx executes .xinitrc and runs until .xinitrc quits*

* we say when .xinitrc quits, but the control process (what startx is waiting for to finish) can be 'passed' to another command via 'exec <command>'

The manual entry for bash explains exec as follows
Quote:exec
... it replaces the shell without creating a new process ...

Given the following sample shell script
Code:
#!/bin/sh

echo command1
exec echo command2
echo command3

You will see the following output
Code:
rbuckland@itasca:~$ sh test
command1
command2

Simply put, the 3rd command never runs because 'exec echo command2' executes and takes control of the shell process.
Going back to the sample in this thread,

Code:
#!/bin/bash
exec /usr/bin/xbmc --standalone

the exec is passing the "control" to xbmc. Now remeber, when the controlling process run by startx finishes, startx finishes.
The trick is two fold,
(1) Keep the control in the .xinitrc
(2) Get .xinitrc to restart xbmc when it quits.

Under normal circumstances, the X session is tied to the "executing process" which has control, normally this is the window manager. In the example directly above, the exec passes control to xbmc.

If we change the above .xinitrc to look like the following ...
Code:
#!/bin/bash
/usr/bin/xbmc --standalone

... then the control is kept with .xinitrc, solving our step (1) .
The exec is no longer there, which means that after xbmc quits, control returns to the .xinitrc script.

Now for part (2). What we will do is get .xinitrc to keep xbmc running, even after it quits, by restarting it.

*The Answer*
To do this simply change the script so it runs xbmc in a loop...

Code:
#!/bin/bash
while [ 1 ]
do
  /usr/bin/xbmc --standalone
done

Now, each time xbmc quits, .xinitrc will relaunch it.
If you need to stop this (for some reason), just ssh into your box from somewhere (or grab a console) and kill the .xinitrc, or the startx script and the "login" will drop out of X.

cheers.
Reply


Messages In This Thread
[No subject] - by malloc - 2008-10-06, 07:05
[No subject] - by althekiller - 2008-10-06, 07:52
[No subject] - by QuietTime - 2008-10-07, 02:09
[No subject] - by MrCerulean - 2008-10-07, 17:39
[No subject] - by proctor - 2008-10-08, 00:42
[No subject] - by MrCerulean - 2008-10-08, 01:29
[No subject] - by covert - 2008-10-08, 06:41
[No subject] - by Chaos_666 - 2008-10-08, 10:53
[No subject] - by proctor - 2008-10-08, 16:15
[No subject] - by MrCerulean - 2008-10-08, 17:16
[No subject] - by QuietTime - 2008-10-08, 23:57
[No subject] - by covert - 2008-10-09, 02:59
[No subject] - by tomsun - 2008-10-09, 09:53
[No subject] - by onderduiker - 2008-10-09, 17:26
[No subject] - by covert - 2008-10-10, 01:58
[No subject] - by onderduiker - 2008-10-10, 21:46
keep the X session running when quitting xbmc - by pefdus - 2008-10-15, 14:30
[No subject] - by Chaos_666 - 2008-10-15, 20:58
selectable at grub? - by zerobravo - 2008-10-26, 18:13
[No subject] - by topfs2 - 2008-10-26, 18:51
[No subject] - by twood - 2008-10-28, 00:04
[No subject] - by topfs2 - 2008-10-28, 08:04
[No subject] - by Chaos_666 - 2008-10-28, 11:11
[No subject] - by twood - 2008-10-28, 11:21
[No subject] - by topfs2 - 2008-10-28, 12:02
[No subject] - by twood - 2008-10-29, 00:23
[No subject] - by Chaos_666 - 2008-10-29, 00:40
[No subject] - by kernel - 2008-10-29, 01:11
[No subject] - by Chaos_666 - 2008-11-03, 19:26
[No subject] - by twood - 2008-11-04, 09:53
[No subject] - by ringgh0st - 2008-11-09, 18:25
[No subject] - by Kryspy - 2008-11-09, 18:40
[No subject] - by Kryspy - 2008-11-11, 15:04
[No subject] - by FoolsRun - 2008-11-11, 17:32
[No subject] - by Kryspy - 2008-11-11, 19:18
[No subject] - by frostwork - 2008-11-11, 23:30
[No subject] - by Kryspy - 2008-11-12, 13:52
[No subject] - by pike - 2008-11-12, 14:30
[No subject] - by frostwork - 2008-11-12, 16:51
Problems - by sexus6 - 2008-11-13, 13:07
[No subject] - by frostwork - 2008-11-13, 13:22
[No subject] - by cejstrup - 2008-11-13, 15:56
[No subject] - by PainToad - 2008-11-16, 13:11
[No subject] - by Morgyn - 2008-11-17, 06:19
[No subject] - by PainToad - 2008-11-18, 13:34
[No subject] - by zyxbox - 2008-11-20, 00:37
[No subject] - by PainToad - 2008-11-21, 04:25
[No subject] - by IG82 - 2008-11-21, 16:33
[No subject] - by IG82 - 2008-11-21, 19:36
[No subject] - by zyxbox - 2008-11-23, 18:13
a couple of notes - by oldnemesis - 2008-11-27, 11:24
[No subject] - by Gurney - 2008-11-30, 10:49
[No subject] - by gilgongo - 2008-12-11, 23:25
[No subject] - by delneet - 2009-01-03, 15:34
[No subject] - by hitman - 2009-01-05, 11:22
[No subject] - by rodercot - 2009-01-17, 15:30
[No subject] - by hitman - 2009-01-18, 11:35
[No subject] - by timecmdr - 2009-01-18, 13:55
[No subject] - by rodercot - 2009-01-18, 15:08
[No subject] - by delneet - 2009-01-19, 11:10
[No subject] - by MP3HiFi - 2009-03-30, 22:01
NO SOUND after doing all steps - by morph3u5 - 2009-05-16, 10:46
[No subject] - by MP3HiFi - 2009-05-16, 13:34
[No subject] - by morph3u5 - 2009-05-16, 17:25
[No subject] - by morph3u5 - 2009-05-19, 19:02
[No subject] - by xanadu1979 - 2009-05-19, 19:11
[No subject] - by MacUsers - 2009-06-03, 13:58
[No subject] - by Giland - 2009-07-10, 20:38
[No subject] - by pinchy - 2009-08-02, 21:05
[No subject] - by arxe41 - 2009-10-02, 23:00
[No subject] - by davidw - 2009-10-05, 16:28
[No subject] - by DDM123 - 2009-10-14, 02:59
[No subject] - by davidw - 2009-10-14, 08:53
[No subject] - by dogk1cker - 2009-10-22, 18:37
[No subject] - by outleradam - 2009-10-23, 03:34
[No subject] - by Freek - 2009-10-23, 21:07
[No subject] - by DaveHope - 2009-10-29, 23:43
[No subject] - by ukasz - 2009-10-30, 00:05
[No subject] - by camdagr8 - 2009-12-07, 15:24
[No subject] - by bolzerrr - 2010-01-25, 19:48
[No subject] - by OldOne - 2010-09-03, 20:11
[No subject] - by acid_junkie - 2010-09-04, 14:11
[No subject] - by osirisjem - 2011-03-19, 21:19
[No subject] - by vikjon0 - 2011-03-29, 20:40
Logout Mark Read Team Forum Stats Members Help
HOW-TO make XBMC for Linux auto start on Ubuntu5