HOW-TO:Autostart Kodi for Linux: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(Updated the wiki for kodi)
Line 1: Line 1:
{{mininav| [[Linux]] }}
{{mininav| [[Linux]] }}
<section begin="intro" />How to automatically start up in XBMC using various Linux distributions.<section end="intro" />
<section begin="intro" />How to automatically start up in Kodi using various Linux distributions.<section end="intro" />


__TOC__
__TOC__
== Upstart init script ==
== Upstart init script ==
Create a '''<code>/etc/init/xbmc.conf</code>''' with following contents.
Create a '''<code>/etc/init/kodi.conf</code>''' with following contents.
<source lang="xml">
<source lang="xml">
# xbmc-upstart
# kodi-upstart
# starts XBMC on startup by using xinit.
# starts Kodi on startup by using xinit.
# by default runs as xbmc, to change edit below.
# by default runs as kodi, to change edit below.
env USER=xbmc
env USER=kodi


description    "XBMC-barebones-upstart-script"
description    "Kodi-barebones-upstart-script"
author          "Matt Filetto"
author          "Matt Filetto"


Line 21: Line 21:


script
script
   exec su -c "xinit /usr/bin/xbmc --standalone -- -nocursor :0" $USER
   exec su -c "xinit /usr/bin/kodi-standalone -- -nocursor :0" $USER
end script
end script
</source><br />
</source><br />


{{note|<code> -- -nocursor</code> option '''kills all X cursor''' on XBMC startup and does not interfere with mouse use/operation}}
{{note|<code> -- -nocursor</code> option '''kills all X cursor''' on Kodi startup and does not interfere with mouse use/operation}}


You may have to edit '''<code>/etc/X11/Xwrapper.config</code>''' and replace the last line that says:
You may have to edit '''<code>/etc/X11/Xwrapper.config</code>''' and replace the last line that says:
Line 39: Line 39:
</source><br />
</source><br />


XBMC will now auto-start on boot and restart/respawn if killed or crashed.
Kodi will now auto-start on boot and restart/respawn if killed or crashed.


== Modify the inittab ==
== Modify the inittab ==

Revision as of 10:39, 29 March 2015

Home icon grey.png   ▶ Linux ▶ HOW-TO:Autostart Kodi for Linux

How to automatically start up in Kodi using various Linux distributions.

Upstart init script

Create a /etc/init/kodi.conf with following contents.

# kodi-upstart
# starts Kodi on startup by using xinit.
# by default runs as kodi, to change edit below.
env USER=kodi

description     "Kodi-barebones-upstart-script"
author          "Matt Filetto"

start on (filesystem and stopped udevtrigger)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn

script
  exec su -c "xinit /usr/bin/kodi-standalone -- -nocursor :0" $USER
end script


Note: -- -nocursor option kills all X cursor on Kodi startup and does not interfere with mouse use/operation

You may have to edit /etc/X11/Xwrapper.config and replace the last line that says:

allowed_users=console

to

allowed_users=anybody


Kodi will now auto-start on boot and restart/respawn if killed or crashed.

Modify the inittab

This was tested on Arch Linux.

To automatically start xbmc on your system, do the following:


First you need to make some changes to /etc/inittab. Comment out (add a #) to this line:

id:3:initdefault

to

#id:3:initdefault

and uncomment

id:5:initdefault

Then add this line to the bottom:

x:5:wait:login -f <YOUR_XBMC_USERNAME> </dev/tty7 &>/dev/tty7

Using wait instead of respawn means that you can exit out of xbmc into the console.


  • NOTE*: This is a security hole as it autologins a dedicated xbmc user without asking for a password!


Now that we have the user logged in we need it to auto start XBMC. In ~/.xinitrc add the following to the end of the file (after removing/commenting any other exec lines that start a windowmanager):

exec ck-launch-session xbmc


Add this line to your ~/.bash_profile

[[ $(tty) = "/dev/tty7" ]] && exec startx </dev/null &>/dev/null


And create a hushlogin file to suppress login messages.

touch ~/.hushlogin


Lastly, for the magic sauce that makes this work, add dbus to your daemons in /etc/rc.conf.

DAEMONS=(... dbus ...)


You're finished. Next time you reboot you should be greeted with XBMC.

Add a new init script

This method works well under Debian. The current configuration is a HTPC running Debian Squeeze, with no window manager installed. The main goal here is to start an Xserver only for XBMC. It allows also to specify which user will start / own the XBMC process. This method will not work if you have a window manager installed (however, it should not be hard to modify the script to suit your needs)

  • Create a new script under /etc/init.d/. Call it xbmc
  • Change the rights, in order to allow it to be executable.
# chmod a+x /etc/init.d/xbmc
  • copy the code under in the file. Modify the variables to suit your configuration:
#! /bin/sh

### BEGIN INIT INFO
# Provides:          xbmc
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of XBMC
# Description:       starts instance of XBMC using start-stop-daemon and xinit
### END INIT INFO

############### EDIT ME ##################

# path to xinit exec
DAEMON=/usr/bin/xinit

# startup args
DAEMON_OPTS=" /usr/local/bin/xbmc --standalone -- :0"

# script name
NAME=xbmc

# app name
DESC=XBMC

# user
RUN_AS=sterfield

# Path of the PID file
PID_FILE=/var/run/xbmc.pid

############### END EDIT ME ##################

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo "Starting $DESC"
        start-stop-daemon --start -c $RUN_AS --background --pidfile $PID_FILE  --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
        ;;
  stop)
        echo "Stopping $DESC"
        start-stop-daemon --stop --pidfile $PID_FILE
        ;;

  restart|force-reload)
        echo "Restarting $DESC"
        start-stop-daemon --stop --pidfile $PID_FILE
        sleep 5
        start-stop-daemon --start -c $RUN_AS --background --pidfile $PID_FILE  --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0
  • Test the script by trying to start / stop XBMC with it.
# /etc/init.d/xbmc start
........
# /etc/init.d/xbmc stop
  • If all is ok, you can add the script to your configuration, by issuing a "update-rc.d"
# update-rc.d xbmc defaults
  • If XBMC does not start, you may need to allow X to start from non-consoles. Under Debian/Ubuntu, run:
# dpkg-reconfigure x11-common

and choose "Anyone".

  • You can now reboot the server, XBMC should be started just after the boot sequence.