WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Can't start things at startup...  (Read 6041 times)

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Can't start things at startup...
« 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.
« Last Edit: November 25, 2016, 11:24:09 PM by risshuu »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Can't start things at startup...
« Reply #1 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
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #2 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.

Offline yojk

  • Newbie
  • *
  • Posts: 4
Re: Can't start things at startup...
« Reply #3 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.


« Last Edit: November 26, 2016, 08:20:09 AM by yojk »

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #4 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.
« Last Edit: November 27, 2016, 11:45:04 PM by risshuu »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Can't start things at startup...
« Reply #5 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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Can't start things at startup...
« Reply #6 on: November 28, 2016, 01:25:16 AM »
What is the output of the syript started in bootlocal.sh? Are there any messages?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #7 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.

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #8 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.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Can't start things at startup...
« Reply #9 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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #10 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.

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #11 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.

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Can't start things at startup...
« Reply #12 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.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline risshuu

  • Newbie
  • *
  • Posts: 19
Re: Can't start things at startup...
« Reply #13 on: December 04, 2016, 10:47:35 PM »
Thanks for the suggestion.  I just tried this and it didn't work for me.