Autorun.sh is not getting executed at boot


#1

However if I run autorun.sh manually via terminal, it works fine.

CoreELEC (official): 9.0.1 (Amlogic.arm)
CoreELEC:~ # cat /etc/*-release
NAME="CoreELEC"
VERSION="9.0.1"
ID="coreelec"
VERSION_ID="9.0"
PRETTY_NAME="CoreELEC (official): 9.0.1"
HOME_URL="https://coreelec.org"
BUG_REPORT_URL="https://github.com/CoreELEC/CoreELEC"
BUILD_ID="df47d9506043985aa1dd1f71a79cecd9dacd275d"
COREELEC_ARCH="Amlogic.arm"
COREELEC_BUILD="official"
COREELEC_PROJECT="Amlogic"
CoreELEC:~ # cat /storage/.config/autostart.sh
#!/bin/sh
(
hdparm -B 127 -M 254 -S 120 /dev/sda5
/storage/.opt/bin/python3 /var/media/sda5-usb-ST916031_0AS_536/discord/main.py
) &
CoreELEC:~ # ls -l /storage/.config/autostart.sh
-rwxr-xr-x    1 root     root           133 Mar  8 15:20 /storage/.config/autostart.sh
CoreELEC:~ #

#2

Before calling python3 add sleep 10 - adjust value appropriately. I assume disk is not mounted yet when script starts.
Instead of sleep you could add some loop and wait until disk is mounted.


#3

I put 30 seconds sleep, didn’t work


#4

Then use this instead of a sleep

while [ ! -d /var/media/sda5-usb-ST916031_0AS_536 ]; do
  sleep 1
done

#5

Nope, not working at boot. Starting manually works fine.

Using username "root".
##############################################
#                  CoreELEC                  #
#            https://coreelec.org            #
##############################################

CoreELEC (official): 9.0.1 (Amlogic.arm)
CoreELEC:~ # sh /storage/.config/autostart.sh
CoreELEC:~ #
/dev/sda5:
 setting Advanced Power Management level to 0x7f (127)
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 setting acoustic management to 254
SG_IO: bad/missing sense data, sb[]:  70 00 0b 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 setting standby to 120 (10 minutes)
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 APM_level      = 127
 acoustic      = not supported

W,2019-03-08 16:27:16,879,discord.client,144: PyNaCl is not installed, voice will NOT be supported
I,2019-03-08 16:27:16,897,__main__,260: Starting BOT...
W,2019-03-08 16:27:18,220,discord.gateway,417: Unknown event SESSIONS_REPLACE.
I,2019-03-08 16:27:18,509,__main__,62: client.user.name:********* client.user.id:***************************

CoreELEC:~ # cat /storage/.config/autostart.sh
#!/bin/sh
(
while [ ! -d /var/media/sda5-usb-ST916031_0AS_536 ]; do
sleep 1
done

hdparm -B 127 -M 254 -S 120 /dev/sda5
/storage/.opt/bin/python3 /var/media/sda5-usb-ST916031_0AS_536/discord/main.py
) &

#6

Then your values from hdparm are overwritten somewhere else. Try my loop + add extra sleep 10 after loop is done.


#7

not, not working. I think the problem is not delay or external hdd not getting mounted.
I think the problem is autorun.sh is not getting executed at all

#!/bin/sh
(
dmesg > /storage/dmesg.log

while [ ! -d /var/media/sda5-usb-ST916031_0AS_536 ]; do
sleep 1
done
sleep 10

hdparm -B 127 -M 254 -S 120 /dev/sda5
/storage/.opt/bin/python3 /var/media/sda5-usb-ST916031_0AS_536/discord/main.py
) &

And /storage/dmesg.log is not being created


#8

I’m going to try a fresh install


#10

Can you post result of
systemctl status kodi-autostart.service -l --no-pager


#11

I disabled kodi and eventlircd because I’m using tvheadend server only.
Does this affect autorun.sh?

CoreELEC:~ # systemctl status kodi-autostart.service -l --no-pager
● kodi-autostart.service - Kodi user autostart script
   Loaded: loaded (/usr/lib/systemd/system/kodi-autostart.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

#12

autostart.sh is execute from kodi-autostart.service which is needed by kodi.
No kodi -> no autostart :slight_smile:


#13

Try

cp /usr/lib/systemd/system/kodi-autostart.service /storage/.config/system.d
sed -i "s|WantedBy=kodi.service|WantedBy=graphical.target|" /storage/.config/system.d/kodi-autostart.service

#14

Damn! I’ve been trying to solve this for two days :slight_smile:
So what are my options to run my discord bot at boot? Would systemd service work?


#15

Yes, try service like this - with different ExecStart :slight_smile:

[Unit]
Description=autostart script
Before=kodi.service
After=network-online.target graphical.target
ConditionPathExists=/storage/.config/autostart.sh

[Service]
Type=oneshot
Environment=HOME=/storage
ExecStart=-/bin/sh -c ". /etc/profile; exec /bin/sh /storage/.config/autostart.sh"
RemainAfterExit=yes

[Install]
WantedBy=graphical.target

#16

Now I’m starting my discord bot as systemd service like below. Thank you!

[Unit]
Description=My Discord Bot
After=network-online.target multi-user.target
ConditionPathExists=/var/media/sda5-usb-ST916031_0AS_536/discord/main.py

[Service]
Type=simple
ExecStart=/storage/.opt/bin/python3 /var/media/sda5-usb-ST916031_0AS_536/discord/main.py

[Install]
WantedBy=multi-user.target