# Run X11 app at startup, no DE



## thedude22 (Nov 18, 2017)

I'm trying to figure out the proper way to run an X application at boot.  I'm trying to run kodi on an htpc.  I do not have a desktop environment installed.  I can manually run kodi from the terminal with 
	
	



```
xinit kodi
```

I'm trying to set up a script in /usr/loca/etc/rc.d to do this at startup.  Should I be using xinitrc instead?  I don't really understand how it words.  I tried reading the script but my shell script knowledge is horrible.

Here is my /usr/local/etc/rc.d/kodi

```
#!/bin/sh

. /etc/rc.subr

name="kodi"
rcvar="${name}_enable"
load_rc_config {name}

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
start_cmd="xinit kodi"
start_precmd="cd /home/htpc"
stop_cmd=":"

: ${kodi_user:=htpc}


run_rc_command "$1"
```
This fails because of file permissions.  I think this is what's going on.  Kodi tries to write files at ~/, but this script is working from / and tries to write there instead?

```
$ service kodi start


X.Org X Server 1.18.4
Release Date: 2016-07-19
X Protocol Version 11, Revision 0
Build Operating System: FreeBSD 11.0-RELEASE-p12 amd64
Current Operating System: FreeBSD HTPC 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
Build Date: 10 October 2017  01:14:51AM

Current version of pixman: 0.34.0
    Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Fri Nov 17 19:36:24 2017
(==) Using config directory: "/usr/local/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/local/share/X11/xorg.conf.d"
Could not init logging classes. Log folder error (/.kodi/temp/)
ERROR: Unable to create application. Exiting
Segmentation fault (core dumped)
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
find: /root/.local: Permission denied
find: /var/audit: Permission denied
find: /var/authpf: Permission denied
find: /var/cron/tabs: Permission denied
find: /var/run/ppp: Permission denied
find: /var/run/tpm: Permission denied
find: /var/run/sudo: Permission denied
find: /var/db/entropy: Permission denied
find: /var/db/ipf: Permission denied
find: /var/db/hyperv: Permission denied
find: /var/db/freebsd-update: Permission denied
find: /var/db/ntp: Permission denied
find: /var/db/samba4/private: Permission denied
find: /var/db/sudo: Permission denied
find: /var/heimdal: Permission denied
find: /var/spool/clientmqueue: Permission denied
find: /var/spool/opielocks: Permission denied
find: /var/spool/dma: Permission denied
find: /etc/ntp: Permission denied
cat: /proc/sys/kernel/core_pattern: No such file or directory
cat: /proc/sys/kernel/core_pattern: No such file or directory
usage: dirname string [...]
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
/usr/local/bin/kodi: cannot create //kodi_crashlog-20171117_193626.log: Permission denied
Crash report available at //kodi_crashlog-20171117_193626.log
xinit: connection to X server lost

waiting for X server to shut down (II) Server terminated successfully (0). Closing log file.
```
What is the proper way to do this?  I want to do this without having to log in at all, just boot straight to kodi.

I tried adding to my rc script:

start_precmd="cd /home/htpc"

and/or

kodi_chdir="/home/htpc"
kodi_chroot="/home/htpc"

It doesn't seem like either one of these does anything.


----------



## Phishfry (Nov 18, 2017)

I think Warren has this covered in this thread.
https://forums.freebsd.org/threads/22304/#post-125992


----------



## thedude22 (Nov 18, 2017)

I really need to learn shell scripting better.

This is a nice solution.  Thank you.


----------



## thedude22 (Nov 18, 2017)

Ok Here's another question.  The exit function in kodi does not quite behave as expected.  It does not shut down the x-server and close kodi.  Kodi just freezes and becomes unresponsive as the X-server stays running.  It's not a huge deal as everything else works perfectly so far.  But is it possible to change this?


----------



## Phishfry (Nov 18, 2017)

`pkill X` would shut down X although I am unsure how you would call it from Kodi. `shutdown -p now` would shut down the machine.


----------



## Phishfry (Nov 18, 2017)

What about hitting the power button on the computer? That should shut it down correctly as well.


----------



## thedude22 (Nov 18, 2017)

Phishfry said:


> What about hitting the power button on the computer? That should shut it down correctly as well.


This computer functions also as a server when it's not running kodi.  It needs to stay running.


----------



## Phishfry (Nov 18, 2017)

Maybe look through this..
https://forums.freebsd.org/threads/40539/

`pkill X` is what you need to return to a command prompt.
Perhaps you could bind it to a keyboard action or edit the kodi shutdown button mapping.


----------

