HOW-TO:Autostart Kodi for Linux: Difference between revisions
(Added section explaining how to use the autologin feature of lightdm to autostart kodi) |
Andrebrait (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{mininav| [[Linux]] }} | {{mininav| [[Linux]] }} | ||
<section begin="intro" />How to automatically start up in Kodi using various Linux distributions.<section end="intro" /> | <section begin="intro" />How to automatically start up in Kodi using various Linux distributions. | ||
The main goal of '''most''' of these methods is to start an Xserver only for Kodi. Most of these methods will '''not work''' if you have a window manager installed (however, it should not be hard to modify the scripts to suit your needs). The lightdm method might work if you need to use a window manager. | |||
Choose '''only one''' method from sections 2 and on based on which distribution and init system you're using.<section end="intro" /> | |||
__TOC__ | __TOC__ | ||
== Create a user to run Kodi == | |||
For security reasons, it is recommended (but optional) to use a dedicated user to run Kodi. The user needs access to audio and video devices as well as access the internet if you're going to use any features that require internet access. Most methods present here allow to specify which user will start / own the Kodi process. | |||
Notice the groups might vary from one distro to another. The groups used below are for Debian-based distributions. To create the user (named '''kodi''' here) and give it the necessary permissions, run | |||
<pre> | |||
# adduser kodi | |||
</pre> | |||
Another option is to add a loginless and passwordless user. You can do so by running | |||
<pre> | |||
# adduser --disabled-password --disabled-login --gecos "" kodi | |||
</pre> | |||
Then, assign it to the following groups in order to give it the permissions it needs. | |||
<pre> | |||
# usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input kodi | |||
</pre> | |||
To give it access to the internet, add the group '''netdev''' as well. | |||
== Upstart init script == | == Upstart init script == | ||
Create a '''<code>/etc/init/kodi.conf</code>''' with following contents. | Works on Ubuntu up to version 14.10 (Utopic Unicorn). As of version 15.04 (Vivid Vervet), Ubuntu switched to systemd and adding a systemd script might be prefereable. Create a '''<code>/etc/init/kodi.conf</code>''' with following contents. | ||
<source lang="xml"> | <source lang="xml"> | ||
# kodi-upstart | # kodi-upstart | ||
Line 113: | Line 140: | ||
== Add a new init script == | == 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. | This method works well under Debian up to version 7 (Wheezy). As of version 8 (Jessie), Debian has switched to systemd and adding a systemd init script might be preferable. The current configuration is a HTPC running Debian Squeeze, with no window manager installed. | ||
* Create a new script under '''/etc/init.d/'''. Call it '''kodi''' | * Create a new script under '''/etc/init.d/'''. Call it '''kodi''' | ||
Line 194: | Line 221: | ||
== Add a new systemd script == | == Add a new systemd script == | ||
This method is for systems that use systemd as init system as current versions of Ubuntu | This method is for systems that use systemd as init system such as current versions of Debian (since version 8, Jessie) and Ubuntu (since version 15.04, Vivid Vervet). | ||
* create a new service file under '''/etc/systemd/system''', call it '''kodi.service''' and copy the following code into the file: | * create a new service file under '''/etc/systemd/system''', call it '''kodi.service''' and copy the following code into the file: | ||
Line 225: | Line 252: | ||
........ | ........ | ||
# systemctl stop kodi</pre> | # systemctl stop kodi</pre> | ||
* If Kodi does not start, you may need to allow X to start from non-consoles. Under Debian/Ubuntu, run: | |||
<pre># dpkg-reconfigure x11-common</pre> | |||
and choose "Anyone". | |||
* As of Ubuntu 16.04 (Xenial Xerus), you need to install and reconfigure the package '''xserver-xorg-legacy''' instead: | |||
<pre># apt-get install xserver-xorg-legacy | |||
# dpkg-reconfigure xserver-xorg-legacy</pre> | |||
and choose "Anyone". You'll also need edit the file '''<code>/etc/X11/Xwrapper.config</code>''' and add the following to a new line at the end of the file: | |||
<pre> | |||
needs_root_rights=yes | |||
</pre> | |||
* if you do not experience any issues, make Kodi start automatically | * if you do not experience any issues, make Kodi start automatically | ||
<pre># systemctl enable kodi</pre> | <pre># systemctl enable kodi</pre> | ||
Line 230: | Line 267: | ||
== Use autologin feature of lightdm == | == Use autologin feature of lightdm == | ||
This works if you have a window manager as well. | |||
* Install lightdm | * Install lightdm |
Revision as of 18:48, 24 April 2016
Linux | HOW-TO:Autostart Kodi for Linux |
How to automatically start up in Kodi using various Linux distributions.
The main goal of most of these methods is to start an Xserver only for Kodi. Most of these methods will not work if you have a window manager installed (however, it should not be hard to modify the scripts to suit your needs). The lightdm method might work if you need to use a window manager.
Choose only one method from sections 2 and on based on which distribution and init system you're using.
Create a user to run Kodi
For security reasons, it is recommended (but optional) to use a dedicated user to run Kodi. The user needs access to audio and video devices as well as access the internet if you're going to use any features that require internet access. Most methods present here allow to specify which user will start / own the Kodi process.
Notice the groups might vary from one distro to another. The groups used below are for Debian-based distributions. To create the user (named kodi here) and give it the necessary permissions, run
# adduser kodi
Another option is to add a loginless and passwordless user. You can do so by running
# adduser --disabled-password --disabled-login --gecos "" kodi
Then, assign it to the following groups in order to give it the permissions it needs.
# usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input kodi
To give it access to the internet, add the group netdev as well.
Upstart init script
Works on Ubuntu up to version 14.10 (Utopic Unicorn). As of version 15.04 (Vivid Vervet), Ubuntu switched to systemd and adding a systemd script might be prefereable. 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 up to version 7 (Wheezy). As of version 8 (Jessie), Debian has switched to systemd and adding a systemd init script might be preferable. The current configuration is a HTPC running Debian Squeeze, with no window manager installed.
- Create a new script under /etc/init.d/. Call it kodi
- Change the rights, in order to allow it to be executable.
# chmod a+x /etc/init.d/kodi
- copy the code under in the file. Modify the variables to suit your configuration:
#! /bin/sh ### BEGIN INIT INFO # Provides: kodi # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts instance of Kodi # Description: starts instance of Kodi 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/kodi-standalone -- :0" # script name NAME=kodi # app name DESC=Kodi # user RUN_AS=kodi # Path of the PID file PID_FILE=/var/run/kodi.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 Kodi with it.
# /etc/init.d/kodi start ........ # /etc/init.d/kodi stop
- If all is ok, you can add the script to your configuration, by issuing a "update-rc.d"
# update-rc.d kodi defaults
- If Kodi 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, Kodi should be started just after the boot sequence.
Add a new systemd script
This method is for systems that use systemd as init system such as current versions of Debian (since version 8, Jessie) and Ubuntu (since version 15.04, Vivid Vervet).
- create a new service file under /etc/systemd/system, call it kodi.service and copy the following code into the file:
[Unit] Description = Kodi Media Center # if you don't need the MySQL DB backend, this should be sufficient After = systemd-user-sessions.service network.target sound.target # if you need the MySQL DB backend, use this block instead of the previous # After = systemd-user-sessions.service network.target sound.target mysql.service # Wants = mysql.service [Service] User = kodi Group = kodi Type = simple #PAMName = login # you might want to try this one, did not work on all systems ExecStart = /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/bin/kodi-standalone -- :0 -nolisten tcp vt7 Restart = on-abort RestartSec = 5 [Install] WantedBy = multi-user.target
- modify the variables (user, group, paths...) to match your configuration. Save the file.
- try to start (and stop) Kodi to make sure the script is working properly
# systemctl start kodi ........ # systemctl stop kodi
- If Kodi 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".
- As of Ubuntu 16.04 (Xenial Xerus), you need to install and reconfigure the package xserver-xorg-legacy instead:
# apt-get install xserver-xorg-legacy # dpkg-reconfigure xserver-xorg-legacy
and choose "Anyone". You'll also need edit the file /etc/X11/Xwrapper.config
and add the following to a new line at the end of the file:
needs_root_rights=yes
- if you do not experience any issues, make Kodi start automatically
# systemctl enable kodi
- reboot and you're done
Use autologin feature of lightdm
This works if you have a window manager as well.
- Install lightdm
sudo apt-get install lightdm
- Modify /etc/lightdm/lightdm.conf and set the following settings under section [Seat:*]:
[Seat:*] autologin-user=kodi autologin-session=kodi
- Reboot and you're done