WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Autostart of Installed Binary  (Read 2540 times)

Offline hogkite

  • Newbie
  • *
  • Posts: 14
Autostart of Installed Binary
« on: November 27, 2020, 05:34:14 PM »
New to PiCore, just got up and running today  ;) I've read up on the basics as described in "Into the Core" and searched around the forum but struggling with something and need some guidance please.

I have created a directory for a project I've downloaded. The project contains a binary and some supporting xml files etc. I realise I should probably create an extension and set it to load at boot but I wanted to get this up and running asap and perhaps look at extensions later.

The new directory persists and I've included it in the backup process and can start the binary manually no problem. Having read some posts it seems that the recommended way to autostart this binary is to include the required command in /opt/bootlocal.sh?

I seem to be struggling to get this to work consistently, I suspect it's to do with ownership/permissions but not sure? I'm logging into piCore as user tc (noautologin). When I initially added the startup command it didn't work because of permissions, so I added sudo if front of the start command. This worked. However, I saw a post in the forum suggesting to another user that it was best to change ownership of bootlocal.sh from root:root to tc:staff and remove the sudo from the commands. I did this but it doesn't work and now adding sudo back in it still doesn't work. I've put the ownership back to root:root and that doesn't work.....suspect I might be getting myself in a twist.

I can probably get it to work by hook or by crook but I would like to know the correct way to achieve this for future reference, could someone offer some assistance please? Thanks

PS....the wiki doesn't seem to work for me, is there an issue with it?

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Autostart of Installed Binary
« Reply #1 on: November 27, 2020, 07:03:08 PM »
Hi, hogkite!

There are some troubles with the recent version of Wiki, You can find a little bit outdated version at  http://wiki.tinycorelinux.net/doku.php?id=wiki:start

I use x86 TinyCore, but probably Your issue is not Raspberry specific, so I will try to describe how it works in x86 TC.
bootlocal.sh is executed once per boot by root user, so I think You don't need to change  Your binary ownership. If some software must to be executed once per login, You can envoke it from the ~/.profile of the corresponding user. For example /home/bear/.profile will be executed at each logging of the "bear" user.
Additional possibilities for X startup files, they are located in /usr/local/etc/X.d and in Your home dir ~/.X.d.

Have a nice Core!
« Last Edit: October 27, 2022, 09:35:22 PM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11590
Re: Autostart of Installed Binary
« Reply #2 on: November 27, 2020, 10:07:59 PM »
Hi hogkite
Welcome to the forum.

...  When I initially added the startup command it didn't work because of permissions, so I added sudo if front of the start command. This worked. However, I saw a post in the forum suggesting to another user that it was best to change ownership of bootlocal.sh from root:root to tc:staff and remove the sudo from the commands. ...
bootlocal.sh runs as root, so  sudo  is not necessary. I change my bootlocal.sh to  root:staff  so I don't have to remember
to use sudo when editing it. That's just my preference.

Things that need to run before a GUI are started (like kmaps) should go into  /opt/bootsync.sh.
Things that need to run after a GUI are started (like starting a GUI app) should go into  ~/.X.d.
Things that are not sensitive to when they are started can go into  /opt/bootlocal.sh  which runs in the background.


Offline hogkite

  • Newbie
  • *
  • Posts: 14
Re: Autostart of Installed Binary
« Reply #3 on: November 28, 2020, 04:22:10 AM »
Thanks jazzbiker and Rich

Still struggling with this I'm afraid.

@jazzbiker I've discounted invoking it from the tc user ~/.profile as I want this to start after the boot completes regardless of whether the tc user has logged in or otherwise, plus I have set the system up specifically to require password login for tc user.

@Rich I've tried again with bootlocal.sh but not joy. I've attached some screenshots that may help in determining what the issue might be?

The first shows the ownership/permissions of bootlocal.sh (I've put the ownership/permissions back to the way I believe they were when originally installed)
The second shows the contents of the bootlocal.sh file (the last line is the binary I'm trying to autostart after boot)
The third is just proving that the same command for the binary in bootlocal.sh works from the command line in my home directory

Very strange?


« Last Edit: November 28, 2020, 04:24:56 AM by hogkite »

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Autostart of Installed Binary
« Reply #4 on: November 28, 2020, 04:57:00 AM »
Hi, hogkite!

What will be the behavior of Your utility in case of network down? Maybe there are no interfaces upped on the moment it is envoked from bootlocal.sh? I think You can use dummy sleeps before calling Your utility or play with "wait" shell builtin.

P.S. I don't know what eth0.sh is doing, but You can try start it not backgrounded - exclude '&'.
« Last Edit: November 28, 2020, 05:06:38 AM by jazzbiker »

Offline hogkite

  • Newbie
  • *
  • Posts: 14
Re: Autostart of Installed Binary
« Reply #5 on: November 28, 2020, 05:39:00 AM »
hi jazzbiker

That was it!!  :D I included a sleep timer of 30 seconds in the bootlocal.sh and it's now working fine.

etho.sh is just a script to configure a static IP address for my piCore box.

Thanks for your help



Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11590
Re: Autostart of Installed Binary
« Reply #6 on: November 28, 2020, 10:04:46 AM »
Hi hogkite
... I included a sleep timer of 30 seconds in the bootlocal.sh and it's now working fine. ...
If you need to wait for your network to be up, you could create a file called  WaitFor_eth0.sh  in your  /opt  directory:
Code: [Select]
#!/bin/sh
# Wait for network to come up
SEC="60"
while [ $SEC -gt 0 ]
do
SEC=$(($SEC - 1))
ifconfig | grep -q "Bcast:" && break
sleep 1
done
if [ $SEC -le 0 ]
then
# Network never came up.
exit 1
fi
# Place commands that depend on the network being up here.
/usr/local/bin/UPnPBridge/Bin/...................
This will wait only as long as it takes for the network to come up, or time out and exit if it doesn't.

The call it from  bootlocal.sh  like this:
Code: [Select]
/opt/WaitFor_eth0.sh &

Offline hogkite

  • Newbie
  • *
  • Posts: 14
Re: Autostart of Installed Binary
« Reply #7 on: November 28, 2020, 10:28:50 AM »
Even better, thanks Rich

I'll give it a try.