Sunday, July 15, 2012

XBMC - auto login, auto start, auto restart

This info is old and probably not very useful to anyone anymore.

This is a quick and dirty way of getting Ubuntu server to auto login the user xbmc and have that user start XBMC on boot and restart it if it crashes. There is no login-manager, no WM/DE, no nothing, just XBMC. And for me, that is enough.

Update 1: Checking if logged in at tty1 before starting the xbmc-neverending-loop. This as not to interfere with ssh-logins and/or logins on other ttys with the xbmc user.
Update 2: I think you could trim the startx line in the loop-script to only "startx /usr/bin/xbmc" but I'm not on Ubuntu anymore so I'll leave it as is for now seeing as I can't test it.

First of all, I build XBMC from source and run it on a minimal (or as minimal as I could get it at least) Ubuntu server installation which is why I use this method. I'm guessing nothing of this would be necessary if you install XBMC from the official team-xbmc repo on a Ubuntu desktop installation.

I have xbmc installed in /usr/bin. I've heard reports of people having it in /usr/local/bin so heads up, you'll need to change the path further down if that is the case for you.

Ubuntu uses Upstart, not System V and as such doesn't have an /etc/inittab which I've seen mentioned in a lot of auto-login posts on forums and blogs. What it has instead is /etc/init/ttyX.conf (or /etc/event.d/ttyX.conf depending on Ubuntu-version) which is basically the same thing.

Autologin
First, install mingetty.
apt-get install mingetty
Then edit /etc/init/tty1.conf
Change
exec /sbin/getty -8 38400 tty1
to
exec /sbin/mingetty --autologin xbmc tty1
(change xbmc to whichever user you have running xbmc)

That's it, reboot and tty1 should get auto-logged-in with user xbmc.

Autostart (and restart) XBMC
Now edit/create .bash_profile (or .bash_login or .profile, it doesn't matter) in /home/xbmc and enter the following.
if tty | fgrep tty1; then
 while [ 1 -eq 1 ]; do
  startx /etc/X11/Xsession /usr/bin/xbmc

  sleep 5
 done
fi

See, I told you it would be dirty.
This starts XBMC when user xbmc logs in and if XBMC crashes (what?) it restarts it after 5s.

Easy peasy! ^_^

Oh btw, Pandaface? Mipxa says hello.