# Custom autostart script not working

**URL:** https://dietpi.com/forum/t/custom-autostart-script-not-working/1960
**Category:** Troubleshooting
**Created:** [12 February 2018 13:05 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960 "2018-02-12T13:05:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gurnarok](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gurnarok](https://dietpi.com/forum/u/gurnarok)
#### Post date: [12 February 2018 13:05 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/1 "2018-02-12T13:05:47Z")

</div>

Hi, I am having a problem with custom script.

```nohighlight
#!/bin/bash
#---Examples---

# - Chromium
#xinit chromium

# - LXDE
#startx

# - Print hello
#echo -e "Hello"

#---Put your code below this line---
echo 123 > /root/bootok

```

```nohighlight
root@Mars:~# ls -lh /root/
total 92K
drwxr-xr-x 4 root root 4.0K Feb 12 11:34 configs
drwxr-xr-x 2 root root 4.0K Jan 31 07:20 Desktop
-rw-r--r-- 1 root root 0 Jan 31 08:07 kodi_crashlog-20180131_080705.log
-rw-r--r-- 1 root root 82K Feb 1 18:31 kodi_crashlog-20180201_183123.log

```

In boot screen, I see a strange message:

```nohighlight
Started DietPi autostart (Custom /var/lib/dietpi/dietpi-autostart/custom.sh).
/bin/echo: /bin/echo: cannot execute binary file

```

So what is going on? How can I fix this? I am trying to delay Kodi from starting, giving MariaDB time to start.

---

<div class="post-metadata">

### Author: ![Fourdee](https://dietpi.com/forum/user_avatar/dietpi.com/fourdee/32/11_2.png) [@Fourdee](https://dietpi.com/forum/u/Fourdee)
#### Post date: [12 February 2018 13:54 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/2 "2018-02-12T13:54:08Z")

</div>

Hi,

Confirmed, running some checks, will post back in a bit.

---

<div class="post-metadata">

### Author: ![Fourdee](https://dietpi.com/forum/user_avatar/dietpi.com/fourdee/32/11_2.png) [@Fourdee](https://dietpi.com/forum/u/Fourdee)
#### Post date: [12 February 2018 14:05 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/3 "2018-02-12T14:05:20Z")

</div>

Bug our end (thanks for letting us know), please copy/paste all into term:

```nohighlight
cat << _EOF_ > /etc/systemd/system/dietpi-autostart_custom.service
[Unit]
Description=DietPi autostart (Custom /var/lib/dietpi/dietpi-autostart/custom.sh)
After=dietpi-boot.service dietpi-ramdisk.service dietpi-ramlog.service rc-local.service
Requires=dietpi-boot.service dietpi-ramdisk.service

[Service]
Type=idle
ExecStartPre=/bin/bash -c 'echo -e "Starting DietPi-Autostart (Custom) script"'
ExecStartPre=$(which chmod) +x /var/lib/dietpi/dietpi-autostart/custom.sh
ExecStart=/bin/bash -c /var/lib/dietpi/dietpi-autostart/custom.sh
StandardOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
_EOF_
systemctl daemon-reload
systemctl restart dietpi-autostart_custom.service

```

Will also be resolved in v6.2 update.  
test:

```nohighlight
root@DietPi:~# ls -lha
..
-rw-r--r-- 1 root root 4 Feb 12 14:03 bootok
..

```

---

<div class="post-metadata">

### Author: ![gurnarok](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gurnarok](https://dietpi.com/forum/u/gurnarok)
#### Post date: [12 February 2018 15:29 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/4 "2018-02-12T15:29:19Z")

</div>

Thanks!

I made a dirty hack, adding sleep command into /DietPi/dietpi/misc/start\_kodi

```nohighlight
        #/////////////////////////////////////////////////////////////////////////////////////
        # Main Loop
        #/////////////////////////////////////////////////////////////////////////////////////
        #-----------------------------------------------------------------------------------
        #Raspberry Pi
        if (( $G_HW_MODEL < 10 )); then

                sleep 2m
                kodi-standalone

        #Everything else

```

---

<div class="post-metadata">

### Author: ![gurnarok](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gurnarok](https://dietpi.com/forum/u/gurnarok)
#### Post date: [13 February 2018 08:27 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/5 "2018-02-13T08:27:00Z")

</div>

Ok, so I added the code and it works. But kodi is having problems starting up, I keep getting error messages when kodi tries to start.

```nohighlight
terminate called after throwing an instance of 'std::logic_error'
  what(): basic_string::_M_construct null not valid
Aborted
Cras report available at /kodi_crashlog-20180213_003222.log
terminate called after throwing an instance of 'std::logic_error'
  what(): basic_string::_M_construct null not valid
Aborted
Cras report available at /kodi_crashlog-20180213_003223.log
terminate called after throwing an instance of 'std::logic_error'
  what(): basic_string::_M_construct null not valid
Aborted
Cras report available at /kodi_crashlog-20180213_003225.log
/usb/bin/kodi --standalone has exited in an unclean state 3 times in the last 6 seconds.
Something is probably wrong

```

And the crash logs only contain

```nohighlight
root@Mars:/# cat kodi_crashlog-20180213_00322*
############## Kodi CRASH LOG ###############

################ SYSTEM INFO ################
 Date: Tue 13 Feb 00:32:22 EET 2018
 Kodi Options:
 Arch: armv7l
 Kernel: Linux 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017
 Release: Raspbian GNU/Linux 9 (stretch)
############## END SYSTEM INFO ##############

############### STACK TRACE #################
gdb not installed, can't get stack trace.
############# END STACK TRACE ###############

################# LOG FILE ##################

Logfile not found in the usual place.
Please attach it separately.
Use pastebin.com or similar for forums or IRC.

############### END LOG FILE ################

############ END Kodi CRASH LOG #############
############## Kodi CRASH LOG ###############

################ SYSTEM INFO ################
 Date: Tue 13 Feb 00:32:23 EET 2018
 Kodi Options:
 Arch: armv7l
 Kernel: Linux 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017
 Release: Raspbian GNU/Linux 9 (stretch)
############## END SYSTEM INFO ##############

############### STACK TRACE #################
gdb not installed, can't get stack trace.
############# END STACK TRACE ###############

################# LOG FILE ##################

Logfile not found in the usual place.
Please attach it separately.
Use pastebin.com or similar for forums or IRC.

############### END LOG FILE ################

############ END Kodi CRASH LOG #############
############## Kodi CRASH LOG ###############

################ SYSTEM INFO ################
 Date: Tue 13 Feb 00:32:25 EET 2018
 Kodi Options:
 Arch: armv7l
 Kernel: Linux 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017
 Release: Raspbian GNU/Linux 9 (stretch)
############## END SYSTEM INFO ##############

############### STACK TRACE #################
gdb not installed, can't get stack trace.
############# END STACK TRACE ###############

################# LOG FILE ##################

Logfile not found in the usual place.
Please attach it separately.
Use pastebin.com or similar for forums or IRC.

############### END LOG FILE ################

############ END Kodi CRASH LOG #############
root@Mars:/#

```

My custom startup script

```nohighlight
root@Mars:~# cat /var/lib/dietpi/dietpi-autostart/custom.sh
#!/bin/bash
#---Examples---

# - Chromium
#xinit chromium

# - LXDE
#startx

# - Print hello
#echo -e "Hello"

#---Put your code below this line---
#rm /mnt/pub_files/*_boot_ok
#touch /mnt/pub_files/$(date +%F__%H_%M)_boot_ok
sleep 2m
/DietPi/dietpi/misc/start_kodi

```

Edit:  
Installed gdb to get something out of the crashlog, got this.

```nohighlight
root@Mars:~# cat /kodi_crashlog-20180213_104756.log
############## Kodi CRASH LOG ###############

################ SYSTEM INFO ################
 Date: Tue 13 Feb 10:47:56 EET 2018
 Kodi Options:
 Arch: armv7l
 Kernel: Linux 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017
 Release: Raspbian GNU/Linux 9 (stretch)
############## END SYSTEM INFO ##############

############### STACK TRACE #################
=====> Core file: /core (2018-02-13 10:47:56.591485956 +0200)
        =========================================
[New LWP 3416]
[New LWP 3417]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
Core was generated by `/usr/lib/arm-linux-gnueabihf/kodi/kodi_v7.bin --lircdev /var/run/lirc/lircd'.
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
[Current thread is 1 (Thread 0x71ed8000 (LWP 3416))]

Thread 2 (Thread 0x71ed7300 (LWP 3417)):
#0 0x76f3a94c in __pthread_cond_wait (cond=0x2cddf30, mutex=0x2cddf68) at pthread_cond_wait.c:186
#1 0x009f1488 in ANNOUNCEMENT::CAnnouncementManager::Process() ()
#2 0x0069f674 in CThread::Action() ()
#3 0x0069feb0 in CThread::staticThread(void*) ()
#4 0x76f33fc4 in start_thread (arg=0x71ed7300) at pthread_create.c:335
#5 0x753e3c68 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:76 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x71ed8000 (LWP 3416)):
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x7533f824 in __GI_abort () at abort.c:89
#2 0x754f3060 in __gnu_cxx::__ verbose_terminate_handler() () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#3 0x754f0db0 in ?? () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#4 0x754f0e24 in std::terminate() () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#5 0x754f1158 in __cxa_throw () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#6 0x755194d4 in std::__throw_logic_error(char const*) () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
#7 0x007ea6cc in ?? ()
#8 0x007ecddc in CApplication::Create() ()
#9 0x006b7988 in XBMC_Run ()
#10 0x003d37ac in main ()
############# END STACK TRACE ###############

################# LOG FILE ##################

Logfile not found in the usual place.
Please attach it separately.
Use pastebin.com or similar for forums or IRC.

############### END LOG FILE ################

############ END Kodi CRASH LOG #############

```

---

<div class="post-metadata">

### Author: ![Fourdee](https://dietpi.com/forum/user_avatar/dietpi.com/fourdee/32/11_2.png) [@Fourdee](https://dietpi.com/forum/u/Fourdee)
#### Post date: [13 February 2018 16:02 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/6 "2018-02-13T16:02:22Z")

</div>

Confirmed with Kodi, I tried a few methods with no success, doesnt seem to like being launched under bash with systemD.  
Needs further investigations, will need to pick this up at a later date.

Simple solution for now is using your hack ([http://dietpi.com/phpbb/viewtopic.php?f=11&t=2832&p=10900#p10866](http://dietpi.com/phpbb/viewtopic.php?f=11&t=2832&p=10900#p10866)) and selecting Kodi as autostart option.  
Just bear in mind, updating DietPi will revert your changes (replaced with latest scripts), so you’ll need to re-add it back in.

---

<div class="post-metadata">

### Author: ![gurnarok](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gurnarok](https://dietpi.com/forum/u/gurnarok)
#### Post date: [13 February 2018 17:30 UTC](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/7 "2018-02-13T17:30:09Z")

</div>

> [@Fourdee](#):
>
> Simple solution for now is using your hack ([Custom autostart script not working - #6 by Fourdee](https://dietpi.com/forum/t/custom-autostart-script-not-working/1960/6)) and selecting Kodi as autostart option.  
> Just bear in mind, updating DietPi will revert your changes (replaced with latest scripts), so you’ll need to re-add it back in.

Would it be possible, to have an option to set a delay (in seconds) when selecting Kodi as autostart.
