Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: risshuu on November 25, 2016, 11:09:39 PM

Title: Can't start things at startup...
Post by: risshuu on November 25, 2016, 11:09:39 PM
I am running picore.

1. I have a script I want to run at startup.  I have tried a few things; currently using:
Code: [Select]
su bob -c "python /home/bob/fauxmo.py" -s /bin/bash in the bootlocal file. So far, nothing has worked.

2. I want cron to start at boot.  I have mounted the boot partition and modified both cmdline.txt and cmdline3.txt by adding cron at the end of it.  Neither start cron.  I have also tried putting
Code: [Select]
/etc/init.d/services/crond start in the bootlocal file.  Nothing works.
Title: Re: Can't start things at startup...
Post by: bmarkus on November 26, 2016, 01:24:29 AM
I am running picore.

1. I have a script I want to run at startup.  I have tried a few things; currently using:
Code: [Select]
su bob -c "python /home/bob/fauxmo.py" -s /bin/bash in the bootlocal file. So far, nothing has worked.


Does it work if you try it in the console?

There are many issues.

- do not use bob, use default tc user
- make sure you really need bash, default is BusyBox ash
- if you need bash, install from repo
- bash is in /usr/local/bin, not /bin
Title: Re: Can't start things at startup...
Post by: risshuu on November 26, 2016, 03:02:37 AM
Yes.  It does.  I have to run it from the command line in order for it to work instead of it running automatically from bootlocal.
Title: Re: Can't start things at startup...
Post by: yojk on November 26, 2016, 08:18:29 AM
Hi,
if you put your script in the bootlocal, it will be startet as root, so why using su bob.
Also try to use absolute path for su and python.


I'm new to piCore too, but I would do it this way:

Try to put:
Code: [Select]
#!/usr/local/bin/python -Oin the header of your python script. Make your script executable:
Code: [Select]
sudo chmod +x /home/bob/fauxmo.py
Then add:
Code: [Select]
/home/bob/fauxmo.py
in /opt/bootlocal.sh

And don't forget to backup.


Title: Re: Can't start things at startup...
Post by: risshuu on November 27, 2016, 11:36:16 PM
Running it as root by just using /home/bob/fauxmo.py in /opt/bootlocal doesn't work.  Not even when changing the first line as you suggested. (I'm using PiCore 8.0, btw)

After a reboot:

Code: [Select]
root@box:~# ps aux | grep faux
 1199 root     grep faux
root@box:~# type python
python is /usr/local/bin/python

Code: [Select]
-rwxr-xr-x    1 bob     nogroup    15.8K Nov 27 21:30 fauxmo.py

Yet, it works fine on the command line; either the way I had it (running as my other user) or running it as root with the first line different.

Code: [Select]
root@box:/home/bob# ./fauxmo.py &
root@box:/home/bob# ps aux | grep fauxmo.py
 1253 root     {fauxmo.py} /usr/local/bin/python -O ./fauxmo.py
 1260 root     grep fauxmo.py


Cron seems to be starting now, though.  I don't know how or why, but maybe adding
Code: [Select]
crond start into bootlocal did it.  At least that works, though.
Title: Re: Can't start things at startup...
Post by: bmarkus on November 28, 2016, 01:22:21 AM
Cron seems to be starting now, though.  I don't know how or why, but maybe adding
Code: [Select]
crond start into bootlocal did it.  At least that works, though.

Well, crond must be started. Otherwise doesn't work.
Title: Re: Can't start things at startup...
Post by: bmarkus on November 28, 2016, 01:25:16 AM
What is the output of the syript started in bootlocal.sh? Are there any messages?
Title: Re: Can't start things at startup...
Post by: risshuu on November 28, 2016, 02:20:53 AM
Cron seems to be starting now, though.  I don't know how or why, but maybe adding
Code: [Select]
crond start into bootlocal did it.  At least that works, though.

Well, crond must be started. Otherwise doesn't work.

Yes; my point was I tried the boot flag, and the line in my first post and neither seemed to work.
Title: Re: Can't start things at startup...
Post by: risshuu on November 28, 2016, 02:22:04 AM
What is the output of the syript started in bootlocal.sh? Are there any messages?

No, there aren't any messages.
Title: Re: Can't start things at startup...
Post by: bmarkus on November 28, 2016, 02:36:02 AM
What is the output of the syript started in bootlocal.sh? Are there any messages?

No, there aren't any messages.
Title: Re: Can't start things at startup...
Post by: risshuu on November 29, 2016, 05:14:58 AM
Okay, so, I don't know why it wasn't working before, but now cron works fine with just the bootcode.  I still can't get my script to start, though.
Title: Re: Can't start things at startup...
Post by: risshuu on December 04, 2016, 05:30:50 AM
I decided to just create a script that fires off every minute via cron.

Code: [Select]
#!/bin/bash

if [ $(ps aux | grep fauxmo.py | grep bob | wc -l) -eq 0 ]
then
su bob -c "python /home/bob/fauxmo.py" -s /bin/bash
fi

This seems to work for now.  I tried it with @reboot as well, but that never worked.
Title: Re: Can't start things at startup...
Post by: Gerrelt on December 04, 2016, 04:07:34 PM
FWIW:
I've started python scripts in bootlocal.sh like this:

Code: [Select]
python /home/tc/squeezelite_switches1.py &
The ampersand (&) makes it a background process, which has to be added otherwise the bootlocal.sh script would wait untile the command was finished before executing the next statements.
Title: Re: Can't start things at startup...
Post by: risshuu on December 04, 2016, 10:47:35 PM
Thanks for the suggestion.  I just tried this and it didn't work for me.