# Restart xbmc via crontab



## Migelo (Jun 19, 2013)

Hi!

Configuration:

9.1 64-bit, default kernel
Nvidia drivers as per the handbook
X.Org on startup
Xfce desktop manager

If I let xbmc open for a few days at idle, at the welcome screen on my HTPC/ZFS file server and then start playing a video, it's not smooth. Every couple of seconds it stops for a fraction of a second and then it goes on. 

Reinstalling xbmc didn't help, what helps is if I kill xbmc and open it up again, works like a charm!

What I'm having trouble with, is restarting xbmc via crontab every night at 2 AM. 

I can kill it via pkill

```
0	2	*	*	*	pkill xbmc.bin
```
 but I can't make it start, I've tried:

```
1	2	*	*	*	xbmc
1	2	*	*	*	/usr/local/bin/xbmc
```

I wrote a simple script that was run by cron and it managed to kill xbmc but not start it. 

I thank you in advance for your support.


----------



## junovitch@ (Jun 21, 2013)

Hello.  Quick question... Are you using /etc/crontab with what you have listed?  If so that also lists the user as shown in the default like below.  However, you wouldn't want to put something like XBMC run as root in /etc/crontab.


```
1	3	*	*	*	root	periodic daily
15	4	*	*	6	root	periodic weekly
30	5	1	*	*	root	periodic monthly
```

If you are using your user and did a `crontab -e` then you should be fine.  You should be able to put them in one line.  You will need the full path like you already have below.  If that doesn't work... I'm not sure and might have to look at it closer.  


```
1	2	*	*	*	pkill xbmc; /usr/local/bin/xbmc
```


----------



## ShelLuser (Jun 22, 2013)

Now, it's been ages since I used X so some of my experience could be dated or worse: I could be completely off here.

Even so; I think you're overlooking a very important aspect here: the console. X uses a specific console, one which is normally added to your environment the very moment you start it. That's why other X programs can determine which console to use to display their output.

As a small sidestep: this console is also how you can easily run two X sessions side by side; simply specify the new console to use when starting X (using startx for example).

Alas; when you use crontab then the process will log on as your user account, but that session won't share the same environment and most definitely won't have any specifications which console to use for any graphical programs.

As such: I can't help wonder if you shouldn't specify which X console this program should use.


----------



## junovitch@ (Jun 22, 2013)

Excellent point.  Maybe something like this would work.


```
1	2	*	*	*	pkill xbmc; export DISPLAY=:0 && /usr/local/bin/xbmc
```

Or define it at the top for all.

```
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
DISPLAY=:0 
1	2	*	*	*	pkill xbmc; /usr/local/bin/xbmc
```


----------



## Migelo (Jun 22, 2013)

It sure is a display thing. If I run this command via SSH it works, but not in crontab. 
	
	



```
export DISPLAY=:0 && /usr/local/bin/xbmc
```

cron logs show the command is being run, but not working as it seems.


----------



## Migelo (Jun 22, 2013)

I got it working. It was just missing some of the pa_th_s as it seems:

```
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
6       6       *       *       *       pkill xbmc.bin
7       6       *       *       *       export DISPLAY=:0 && /usr/local/bin/xbmc
```


----------



## junovitch@ (Jun 22, 2013)

Good work. It would be nice if an ugly workaround wasn't needed but I guess if this was an HTPC that was regularly rebooted it wouldn't be a big deal.


----------



## Migelo (Jun 23, 2013)

Yeah, but a HTPC is only one of its many many roles. 

P.S.: I don't think it's really necessary to fix typos.


----------



## Migelo (Jan 31, 2014)

Hi!

Just want to let you know that I don't have to restart xbmc anymore, it was fixed in an update. (idk which, was not paying attention)


----------

