rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Cronjob starting some but not all jobs...

Tue Feb 24, 2015 1:42 am

Hey, hoping to get some advice from someone who has dealt with this before.

I am running Raspbian, installed via Noobs, have run the sudo apt-get update, sudo apt-get upgrade, sudo rpi-update, and sudo apt-get dist-upgrade, so it should be all up to date.

Everything is running quite well, but I am running into problem getting pyload to auto-start on reboot.

I have added the following lines via sudo crontab -e
@reboot kodi-standalone
@reboot /usr/share/pyload/pyLoadCore.py --daemon
@reboot /home/pi/.btsync/btsync --config /home/pi/.btsync/sync.conf

When I boot my pi up it goes through Noobs, automatically boots into my last used distro (Raspbian), then continues to boot. It gets to the login prompt, waits there briefly, then Kodi launches and takes over the screen. By SSH in I can see what is running and what is not. BTsync is running nicely, and accessible via the web GUI, however, pyload does not start. If I use the terminal and type in /usr/share/pyload/pyLoadCore.py --daemon then it starts and runs just fine. If I enter service pyload start into the terminal it starts just fine. I even tried adding my own script called pyload.sh which contains the /usr/share/pyload/pyLoadCore.py --daemon and that works just fine if entered into /etc/profile (though only AFTER logging in with username and password, whereas I want to start pyload prior to logging in)

I have tried putting @reboot service pyload start into the the cronjob, it does not work
I have tried referencing my pyload.sh script in crontab, it also does not work

I am unsure about why these are not working, and so I am scared to try to add my script into the rc.local for fear of grinding the boot process to a halt if for some reason the requisite services are not available to start pyload at that point in the boot and that is why this isn't working.

I have enabled and examined the cron log and find no errors in it.

What could be the problem, and how can I fix it?

Thanks!

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 2:14 am

Can you run the script in

Code: Select all

.bashrc
:mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 2:38 am

hmm I am not familiar with .bashrc, can you give me an example of what the correct input for my case would be, and I can try it? (program I'm trying to run is at /usr/share/pyload/pyLoadCore.py)

Thanks!

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 2:51 am

rpi25 wrote:hmm I am not familiar with .bashrc, can you give me an example of what the correct input for my case would be, and I can try it? (program I'm trying to run is at /usr/share/pyload/pyLoadCore.py)

Thanks!

Code: Select all

sudo nano .bashrc
and put at the end of it

Code: Select all

sudo sh /home/pi/pyload.sh
or wherever your pyload.sh script is. :mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 2:57 am

Hey instead of you doing all 3 of these in cronjob why not make a single script that launches all 3 of them and put it in

Code: Select all

.bashrc
I guess you can name the script

Code: Select all

startup.sh
:mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 4:49 am

That's a good idea, I will likely do it.

I guess I am a bit confused, why is .bashrc better for cronjob than this? How do either of them compare with init.d? Linix noob here, lol.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 4:56 am

Well, your idea of adding my script for pyload to .bashrc worked like a charm, wizard!

But seriously, where the heck can I read a good primer on all the various ways there are of automating user created scripts? I was really liking cronjob b/c I felt I had a good handle on it, until it stopped working for me, lol. Oh well

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 5:02 am

OK, here's one thing I'm noticing.

Now whenever I SSH into my pi using putty, after putting in the login info it sits there and waits for a prolonged period of time, then pops out with
"Daemon PID XXXX"

I believe it is trying to relaunch my .bashrc line which calls upon my command to start pyLoadCore.py --daemon, each time I am opening a terminal.

This is less than ideal, any way to stop this from happening?

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 6:39 am

rpi25 wrote:OK, here's one thing I'm noticing.

Now whenever I SSH into my pi using putty, after putting in the login info it sits there and waits for a prolonged period of time, then pops out with
"Daemon PID XXXX"

I believe it is trying to relaunch my .bashrc line which calls upon my command to start pyLoadCore.py --daemon, each time I am opening a terminal.

This is less than ideal, any way to stop this from happening?
Your script has no exit so it will continue to run.
Try at the end of your script

Code: Select all

exit 0
:mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
rpdom
Posts: 18140
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 7:10 am

rpi25 wrote:OK, here's one thing I'm noticing.

Now whenever I SSH into my pi using putty, after putting in the login info it sits there and waits for a prolonged period of time, then pops out with
"Daemon PID XXXX"

I believe it is trying to relaunch my .bashrc line which calls upon my command to start pyLoadCore.py --daemon, each time I am opening a terminal.
Yes, that is exactly what it is doing. The .bashrc file is run every time you log into a terminal. If you are going to run it from there you should put some code in to check if it is already running before trying to start it. The "pidof" command is one handy way to find if something is running.
expandables wrote:Your script has no exit so it will continue to run.
Try at the end of your script

Code: Select all

exit 0
No need. If you don't put an exit at the end of the script it will exit with the status of the last command it executed. The reason the rc.local script has exit 0 is that it doesn't want to report failure and hang up the boot if anything in it fails.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Tue Feb 24, 2015 7:00 pm

rpdom wrote:
rpi25 wrote:OK, here's one thing I'm noticing.

Now whenever I SSH into my pi using putty, after putting in the login info it sits there and waits for a prolonged period of time, then pops out with
"Daemon PID XXXX"

I believe it is trying to relaunch my .bashrc line which calls upon my command to start pyLoadCore.py --daemon, each time I am opening a terminal.
Yes, that is exactly what it is doing. The .bashrc file is run every time you log into a terminal. If you are going to run it from there you should put some code in to check if it is already running before trying to start it. The "pidof" command is one handy way to find if something is running.
expandables wrote:Your script has no exit so it will continue to run.
Try at the end of your script

Code: Select all

exit 0
No need. If you don't put an exit at the end of the script it will exit with the status of the last command it executed. The reason the rc.local script has exit 0 is that it doesn't want to report failure and hang up the boot if anything in it fails.
OK cool thanks for confirming that.

I am familiar with pidof, how can I write that into the .bashrc? I assume some sort of if else statement? I've never worked with those outside of my TI-83 back in the day xD haha.

So like maybe,

Code: Select all

if pidof python =/= 0, then /usr/share/pyload/pyLoadCore.py --daemon
The syntax is wrong of course. Can anyone tell me what the right syntax would be?



Also, regarding script exit. I believe that because it is daemonizing the program, that is the exit. For instance, if I launch pyload from the terminal and do not put the --daemon in, it runs through its initialization text then just sits there and does not return to the command prompt. But, if I do put the --daemon in then it takes maybe ~5-10 seconds, and does not show any of the normal output put simply says daemon pid = XXXX and then bumps me back to the command prompt, and pyload is running in the background. So I think based on this the daemon is an exit of sorts?

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Wed Feb 25, 2015 11:12 pm

Can any of you nice folks who have been helping me out in this thread explain what the proper syntax would be to have my .bashrc script check if pyload is already running before trying to relaunch it each time I open a terminal?

Thanks!

User avatar
rpdom
Posts: 18140
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Cronjob starting some but not all jobs...

Thu Feb 26, 2015 10:09 am

Ok, something like this?

Code: Select all

# Check if "pyLoadCore.py" is running. If not, run pyload.sh
if ( ! pidof -x pyLoadCore.py >/dev/null )
then
  sudo sh /home/pi/pyload.sh
fi
You might need to tweak it a bit, but that should give you the general idea.

You could put the test at the beginning of pyload.sh instead, so it'll be checked however it is run.

Code: Select all

# Check if "pyLoadCore.py" is already running first.
if ( pidof -x pyLoadCore.py >/dev/null )
then
  echo "pyLoadCore is already running"
  exit 0
fi
# Now start pyLoadCore.py

User avatar
RaTTuS
Posts: 10741
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Cronjob starting some but not all jobs...

Thu Feb 26, 2015 10:26 am

.bashrc and .bash_profile
are slightly different things

I tend to use things like
http://www.raspberrypi.org/forums/viewt ... =29&t=7192
to auto start scripts

so setup a terminal in inittab to do some stuff that I want
then have in .bashrc something similar to

Code: Select all

if [ $(tty) == /dev/tty1 ]; then
   ./script
fi
this then will check to see if the current terminal is tty1 [i.e. the first one generally] and then it will launch my script


also a lot of stuff should not be run as root [or need to be ]
so if you put things in rc.lcoal they will get run as root unless you do something like :-
su -u username /full/path/to/command with args
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Cronjob starting some but not all jobs...

Fri Feb 27, 2015 12:55 am

OK thanks for the tips, appreciate it!

Return to “Raspberry Pi OS”