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

From Official Kodi Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{outdated}}
<section begin="intro" />How to automatically start up in Kodi using various Linux distributions.


<section begin="intro" /><big>Any or all or any combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop.</big><section end="intro" />


<big>'''This how-to has flaws: Never Ever start Kodi without a window manager!''' (FernetMenta: the author of Kodi's X11 windowing system)</big>
__TOC__
 
 
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__
== Create a Kodi user ==
== 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
To use Kodi full-screen, you only have to create a standard user.


<pre>
<pre>
# adduser kodi
adduser kodi
</pre>
</pre>


Another option is to add a loginless and passwordless user. You can do so by running
== Switch to root ==


<pre>
<pre>
# adduser --disabled-password --disabled-login --gecos "" kodi
su
</pre>
</pre>


Then, assign it to the following groups in order to give it the permissions it needs.
or


<pre>
<pre>
# usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input kodi
sudo su
</pre>
</pre>


To give it access to the internet, add the group '''netdev''' as well.
== Customize LightDM to autologin ==


== Upstart init script ==
You can utilize the ability to customize LightDM data manager by changing the builtin custom configuration file '''50-myconfig.conf''' using '''nano''' or another text editor.
Works on Ubuntu up to version 14.10 (Utopic Unicorn). Stating with version 15.04 (Vivid Vervet), Ubuntu has 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">
# 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"
<pre>
author          "Matt Filetto"
mkdir /etc/lightdm/lightdm.conf.d
nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf
</pre>


start on (filesystem and stopped udevtrigger)
Inside this new file add the following text.
stop on runlevel [016]


# tell upstart to respawn the process if abnormal exit
<pre>
respawn
[SeatDefaults]
autologin-user=kodi
</pre>


script
== Configure Kodi to autostart ==
  exec su -c "xinit /usr/bin/kodi-standalone -- -nocursor :0" $USER
end script
</source><br />


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


You may have to edit '''<code>/etc/X11/Xwrapper.config</code>''' and replace the last line that says:
<pre>
ln -s /usr/bin/kodi ~/.config/autostart
</pre>


<source lang="xml">
If Kodi is not installed at the standard path, find it using the '''which''' command.
allowed_users=console
</source>


to
<pre>
which kodi
</pre>


<source lang="xml">
== Disable / enable the login prompt ==
allowed_users=anybody
</source><br />


Kodi will now auto-start on boot and restart/respawn if killed or crashed.
You can disable the graphical login prompt.


== Modify the inittab ==
<pre>
systemctl set-default multi-user.target
</pre>


This was tested on Arch Linux.
To enable it again use.


To automatically start xbmc on your system, do the following:
<pre>
systemctl set-default graphical.target
</pre>


== Create custom Xsession script ==


First you need to make some changes to <code>/etc/inittab</code>. Comment out (add a #) to this line:
Create a custom Xsession script with a text editor.


<pre>
<pre>
id:3:initdefault
nano ~/.xinitrc
</pre>
</pre>


to
To run Kodi full-screen make sure the text reads:


<pre>
<pre>
#id:3:initdefault
#!/usr/bin/env bash
exec /usr/bin/x-window-manager &
/usr/bin/kodi -fs &
</pre>
</pre>


and uncomment
If you are not sure of the path of X Window Manager, use the which command.


<pre>
<pre>
id:5:initdefault
which x-window-manager
</pre>
</pre>


Then add this line to the bottom:
Use '''sudo''' and the '''.xinitrc''' file to configure '''.xsession'''.


<pre>
<pre>
x:5:wait:login -f <YOUR_XBMC_USERNAME> </dev/tty7 &>/dev/tty7
sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"
</pre>
</pre>


Using wait instead of respawn means that you can exit out of xbmc into the console.
You need to use '''sudo''' to run this command. If you do not have '''sudo''', install it.


<pre>
apt install sudo
</pre>


Remember you can modify use and reuse the '''.xinitrc''' file to configure '''.xsession''' as often as you want. That is the purpose of the file. It does nothing on its own until you associate it with a user.


* NOTE*: This is a security hole as it autologins a dedicated xbmc user without asking for a password!
== Create Xsession for Kodi standalone service ==


Kodi full-screen is not the same Kodi standalone service, which runs in Xserver in the default window manager.


Now that we have the user logged in we need it to auto start XBMC.
In order to use Kodi standalone service, create a Kodi user with no login and no password.
In <code>~/.xinitrc</code> add the following to the end of the file
(after removing/commenting any other exec lines that start a windowmanager):


<pre>
<pre>
exec ck-launch-session xbmc
useradd -c 'kodi user' -u 420 -g kodi -G audio,video,network,optical \
-d /var/lib/kodi -s /usr/bin/nologin kodi
passwd -l kodi > /dev/null
mkdir /var/lib/kodi/.kodi
chown -R kodi:kodi /var/lib/kodi/.kodi
</pre>
</pre>


You can download the zip file for Kodi standalone service from GitHub.


Add this line to your <code>~/.bash_profile</code>
[...//github.com/graysky2/kodi-standalone-service Kodi standalone service on GitHub] won't let me link it!
 
Most systems utilize the client version of the software Kodi standalone service requires.
 
Upgrade to the server versions of the X Window System.


<pre>
<pre>
[[ $(tty) = "/dev/tty7" ]] && exec startx </dev/null &>/dev/null
apt install xauth
apt install xorg
apt install xinit
apt install xserver-xorg-core
apt install xserver-xorg
apt install xserver-common
</pre>
</pre>


You can install Kodi standalone service with one easy command.


And create a hushlogin file to suppress login messages.
<pre>
unzip -p kodi-standalone-service-master/kodi-standalone-service-master/init/kodi.service>/usr/lib/systemd/system/kodi.service
</pre>
 
You can now run Kodi standalone service by running one simple command.


<pre>
<pre>
touch ~/.hushlogin
systemctl start kodi
</pre>
</pre>


 
To run Kodi standalone service at boot, open '''.xinitrc''' with a text editor.
Lastly, for the magic sauce that makes this work, add dbus to your daemons in <code>/etc/rc.conf</code>.


<pre>
<pre>
DAEMONS=(... dbus ...)
nano ~/.xinitrc
</pre>
</pre>


Create a custom Xsession script. Make sure it contains the following text.


You're finished. Next time you reboot you should be greeted with XBMC.
<pre>
#!/usr/bin/env bash
systemctl start /usr/bin/kodi &
</pre>


== Add a new init script ==
Use the '''.xinitrc''' file to configure '''.xsession''' for Kodi standalone service..


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.  
<pre>
sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"
</pre>


* Create a new script under '''/etc/init.d/'''. Call it '''kodi'''
== Create Xsession to login app / WM / DE ==
* Change the rights, in order to allow it to be executable.
<pre># chmod a+x /etc/init.d/kodi</pre>
* copy the code under in the file. Modify the variables to suit your configuration:
<pre>#! /bin/sh


### BEGIN INIT INFO
You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.
# 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 ##################
You do this by creating '''.xinitrc''' script that contains the command to start the WM or DE.


# path to xinit exec
For instance, if you are using FluxBox?
DAEMON=/usr/bin/xinit


# startup args
<pre>
DAEMON_OPTS=" /usr/local/bin/kodi-standalone -- :0"
#!/usr/bin/env bash
exec fluxbox &
/usr/bin/kodi -fs &
</pre>


# script name
The '''-fs''' option is full-screen.
NAME=kodi


# app name
To start Gnome with Kodi full-screen:
DESC=Kodi


# user
<pre>
RUN_AS=kodi
#!/usr/bin/env bash
exec gnome-session &
/usr/bin/kodi -fs &
</pre>


# Path of the PID file
Use the '''.xinitrc''' file to configure '''.xsession''' to create a custom login for any user, not just Kodi.  
PID_FILE=/var/run/kodi.pid


############### END EDIT ME ##################
<pre>
sudo -H -u [username] bash -c "ln -s ~/.xinitrc ~/.xsession"
</pre>


test -x $DAEMON || exit 0
== Add a custom Grub entry ==


set -e
If you want to boot to the CLI and manually launch an app, WM or DE, add a custom grub entry.


case "$1" in
The right way to add a custom grub entry is to copy the menu entry you want to change or duplicate.
  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)
Copy the default Grub configuration file and open it with a text editor on your desktop. If you use a text editor on the CLI, the text will be cut off by the window when copying and pasting.
        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</pre>
<pre>
* Test the script by trying to start / stop Kodi with it.
cp /boot/grub/grub.cfg grub.cfg
<pre># /etc/init.d/kodi start
gedit grub.cfg
........
</pre>
# /etc/init.d/kodi stop</pre>
* If all is ok, you can add the script to your configuration, by issuing a "update-rc.d"
<pre># update-rc.d kodi defaults</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".
* You can now reboot the server, Kodi should be started just after the boot sequence.


== Add a new systemd script ==
Copy the menu entry and paste it into '''40_custom''' with a text editor in the CLI.


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).
<pre>
nano /etc/grub.d/40_custom
</pre>


* create a new service file under '''/etc/systemd/system''', call it '''kodi.service''' and copy the following code into the file:
Where the menu entry contains '''quiet splash''' change it to '''text''' instead.
<pre>[Unit]
Description = Kodi Media Center


# if you don't need the MySQL DB backend, this should be sufficient
You should also change the name of the entry!
After = systemd-user-sessions.service network.target sound.target


# if you need the MySQL DB backend, use this block instead of the previous
I just appended mine with “CLI” for command line interface.
# After = systemd-user-sessions.service network.target sound.target mysql.service
# Wants = mysql.service


[Service]
You can the boot to the CLI of your operating system.
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]
You can launch Kodi standalone service.
WantedBy = multi-user.target
</pre>


* 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
<pre># systemctl start kodi
........
# 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>
<pre>
needs_root_rights=yes
systemctl start kodi
</pre>
</pre>
* if you are using a minimalistic system like Ubuntu Server make sure that xinit and dbus-launch are installed
<pre># sudo apt-get install xorg dbus-x11</pre>
* if you do not experience any issues, make Kodi start automatically
<pre># systemctl enable kodi</pre>
* reboot and you're done


== Use autologin feature of lightdm ==
To launch a WM.


This works if you have a window manager as well.
* Install lightdm
<pre>
<pre>
sudo apt-get install lightdm
fluxbox
</pre>
</pre>


* Modify '''/etc/lightdm/lightdm.conf''' and set the following settings under section '''[Seat:*]''':
To launch a DE.
 
<pre>
<pre>
[Seat:*]
gnome-session
autologin-user=kodi
autologin-session=kodi
</pre>
</pre>
* Reboot and you're done
 
You can either manually launch your apps, boot right into them, or create an Xsession for each user. This is great when you want to create a Kodi user for running Kodi only, and for making sure you can still login to your DE with your regular user account.

Revision as of 04:08, 2 February 2018

Any or all or any combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop.

Create a Kodi user

To use Kodi full-screen, you only have to create a standard user.

adduser kodi

Switch to root

su

or

sudo su

Customize LightDM to autologin

You can utilize the ability to customize LightDM data manager by changing the builtin custom configuration file 50-myconfig.conf using nano or another text editor.

mkdir /etc/lightdm/lightdm.conf.d
nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf

Inside this new file add the following text.

[SeatDefaults]
autologin-user=kodi

Configure Kodi to autostart

Configure Kodi to autostart.

ln -s /usr/bin/kodi ~/.config/autostart

If Kodi is not installed at the standard path, find it using the which command.

which kodi

Disable / enable the login prompt

You can disable the graphical login prompt.

systemctl set-default multi-user.target

To enable it again use.

systemctl set-default graphical.target

Create custom Xsession script

Create a custom Xsession script with a text editor.

nano ~/.xinitrc

To run Kodi full-screen make sure the text reads:

#!/usr/bin/env bash
exec /usr/bin/x-window-manager &
/usr/bin/kodi -fs &

If you are not sure of the path of X Window Manager, use the which command.

which x-window-manager

Use sudo and the .xinitrc file to configure .xsession.

sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"

You need to use sudo to run this command. If you do not have sudo, install it.

apt install sudo

Remember you can modify use and reuse the .xinitrc file to configure .xsession as often as you want. That is the purpose of the file. It does nothing on its own until you associate it with a user.

Create Xsession for Kodi standalone service

Kodi full-screen is not the same Kodi standalone service, which runs in Xserver in the default window manager.

In order to use Kodi standalone service, create a Kodi user with no login and no password.

useradd -c 'kodi user' -u 420 -g kodi -G audio,video,network,optical \
-d /var/lib/kodi -s /usr/bin/nologin kodi
passwd -l kodi > /dev/null
mkdir /var/lib/kodi/.kodi
chown -R kodi:kodi /var/lib/kodi/.kodi

You can download the zip file for Kodi standalone service from GitHub.

[...//github.com/graysky2/kodi-standalone-service Kodi standalone service on GitHub] won't let me link it!

Most systems utilize the client version of the software Kodi standalone service requires.

Upgrade to the server versions of the X Window System.

apt install xauth
apt install xorg
apt install xinit
apt install xserver-xorg-core
apt install xserver-xorg
apt install xserver-common

You can install Kodi standalone service with one easy command.

unzip -p kodi-standalone-service-master/kodi-standalone-service-master/init/kodi.service>/usr/lib/systemd/system/kodi.service

You can now run Kodi standalone service by running one simple command.

systemctl start kodi

To run Kodi standalone service at boot, open .xinitrc with a text editor.

nano ~/.xinitrc

Create a custom Xsession script. Make sure it contains the following text.

#!/usr/bin/env bash
systemctl start /usr/bin/kodi &

Use the .xinitrc file to configure .xsession for Kodi standalone service..

sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"

Create Xsession to login app / WM / DE

You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.

You do this by creating .xinitrc script that contains the command to start the WM or DE.

For instance, if you are using FluxBox?

#!/usr/bin/env bash
exec fluxbox &
/usr/bin/kodi -fs &

The -fs option is full-screen.

To start Gnome with Kodi full-screen:

#!/usr/bin/env bash
exec gnome-session &
/usr/bin/kodi -fs &

Use the .xinitrc file to configure .xsession to create a custom login for any user, not just Kodi.

sudo -H -u [username] bash -c "ln -s ~/.xinitrc ~/.xsession"

Add a custom Grub entry

If you want to boot to the CLI and manually launch an app, WM or DE, add a custom grub entry.

The right way to add a custom grub entry is to copy the menu entry you want to change or duplicate.

Copy the default Grub configuration file and open it with a text editor on your desktop. If you use a text editor on the CLI, the text will be cut off by the window when copying and pasting.

cp /boot/grub/grub.cfg grub.cfg
gedit grub.cfg

Copy the menu entry and paste it into 40_custom with a text editor in the CLI.

nano /etc/grub.d/40_custom

Where the menu entry contains quiet splash change it to text instead.

You should also change the name of the entry!

I just appended mine with “CLI” for command line interface.

You can the boot to the CLI of your operating system.

You can launch Kodi standalone service.

systemctl start kodi

To launch a WM.

fluxbox

To launch a DE.

gnome-session

You can either manually launch your apps, boot right into them, or create an Xsession for each user. This is great when you want to create a Kodi user for running Kodi only, and for making sure you can still login to your DE with your regular user account.