OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Starting automatically Re: Re: Starting automatically



Michael is exactly right about the & at the end of the command to send it to the background and let rc.local complete. I go a few steps further. I send stderr to stdout and I invoke it via nohup to make stop any signals getting sent to it about terminals closing. Using nohup is redundant in rc.local since the system terminal can’t be closed, but it does mean that if I copy and paste the commands to start it on the command line it is always okay.

Back to getting it to run automatically… change the your /etc/rc.local to the following:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %sn" "$_IP"

### Setup the OSPi's RTC
#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
#hwclock -s

### Start the OSPi interval program
#host=$(hostname -I | sed 's/ *$//g')
cd /home/pi/OSPi/
nohup /usr/bin/python $host:$port 2>&1 &

exit 0

This includes two commands (commented out so they won’t run) for using the OSPi’s on board clock as well. There are a few other steps to getting that running so I commented them out here. I’ve also told it to listen on all available interfaces ( so that it can be connected to by local services (like apache) on the loopback interface (