Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Running script to start daemon at boot on Jessie

Wed Mar 09, 2016 11:33 pm

I have tried running a script on boot in Jessie on a RPi3 in order to start a daemon (gpsd)..
This post supplied the info on how to set it up with systemd to run at boot time.

I want to start gpsd at boot towards the device ttyUSB0. My script looks like this:

Code: Select all

#!/bin/sh -e
#Need to wait past boot so everything is done
date "+%Y-%m-%d %H:%M:%S" > /booted.txt
sleep 20
echo "Starting GPSD" >> /booted.txt
gpsd /dev/ttyUSB0 -G -n -F /var/run/gpsd.sock
date "+%Y-%m-%d %H:%M:%S" >> /booted.txt
exit 0
As you can see I have put in a 20s sleep in order to let the system stabilize before starting gpsd.
But when I reboot I can see in the created file /booted.txt that the script executes OK, but still after boot there is no gpsd running.
Here is the booted.txt file:

Code: Select all

2016-03-09 21:24:12
Starting GPSD
2016-03-09 21:24:32
I tested the script by starting it manually (sudo /etc/booted/booted.sh) from the command line and it creates the exact same logfile /booted.txt (with different timestamps of course) and in this case after it returns gpsd is actually running and working.

So why is the script not starting the daemon if running via systemd on boot but succeeds to start gpsd if run by a user (with sudo)? It's not like it is not running as can be verified by the logfile.....
Bo Berglund
Sweden

quinness
Posts: 17
Joined: Thu Mar 10, 2016 12:02 pm

Re: Running script to start daemon at boot on Jessie

Thu Mar 10, 2016 1:13 pm

Same here.
Setup systemv

Code: Select all

root@raspberrypi:~# systemctl status gpsd
● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/lib/systemd/system/gpsd.service; static)
   Active: inactive (dead)
root@raspberrypi:~# systemctl enable gpsd
Synchronizing state for gpsd.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d gpsd defaults
Executing /usr/sbin/update-rc.d gpsd enable
root@raspberrypi:~# shutdown -r now      

Code: Select all

root@raspberrypi:~# shutdown -r now      
...
pi@raspberrypi:~ $ sudo su -
root@raspberrypi:~# ps -aux | head -1 ; ps -aux | grep gps | grep -v grep
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root@raspberrypi:~# systemctl start gpsd
root@raspberrypi:~# systemctl status gpsd
● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/lib/systemd/system/gpsd.service; static)
   Active: active (running) since tor 2016-03-10 14:00:45 CET; 3s ago
 Main PID: 777 (gpsd)
   CGroup: /system.slice/gpsd.service
           └─777 /usr/sbin/gpsd -N -b -N -D 3 /dev/ttyUSB0 -n -F /var/run/gpsd.sock

mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: KPPS RFC2783 fd is 9
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: KPPS caps 1133
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:WARN: KPPS kernel PPS will be used
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: NTPD ntpshm_link_activate: 1
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: device /dev/ttyUSB0 activated
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: running with effective group ID 20
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: running with effective user ID 110
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: startup at 2016-03-10T13:00:46.000Z (1457614846)
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: /dev/ttyUSB0 identified as type NMEA0183, 0.547701 sec @ 9600bps
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.

Code: Select all

● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/lib/systemd/system/gpsd.service; static)
   Active: active (running) since tor 2016-03-10 14:00:45 CET; 3s ago
 Main PID: 777 (gpsd)
   CGroup: /system.slice/gpsd.service
           └─777 /usr/sbin/gpsd -N -b -N -D 3 /dev/ttyUSB0 -n -F /var/run/gpsd.sock

mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: KPPS RFC2783 fd is 9
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: KPPS caps 1133
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:WARN: KPPS kernel PPS will be used
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: NTPD ntpshm_link_activate: 1
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: device /dev/ttyUSB0 activated
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: running with effective group ID 20
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: running with effective user ID 110
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: startup at 2016-03-10T13:00:46.000Z (1457614846)
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:INFO: /dev/ttyUSB0 identified as type NMEA0183, 0.547701 sec @ 9600bps
mar 10 14:00:46 raspberrypi gpsd[777]: gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
OK if started manually through console or systemctl but not automatically.
Raspian Jessie 2016-02-26 _-=* If there are choices, why complain? *=-_
openSUSE LEAP 42.1 (3 pcs) _-=* Uppland, Sweden *=-_

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: Running script to start daemon at boot on Jessie

Thu Mar 10, 2016 1:55 pm

I had first retrieved gpsd via apt-get install, but later found out that it was version 3.11 and the latest release is 3.17.
So I uninstalled it and built gpsd from source instead.
And I was advised not to register it as a service either, just start it with a simple script. It will be running as a daemon if given the right arguments.
So this is why I am searching for a way to run this script once after boot, but no matter how long a sleep I put there it won't run....

An idea:
Maybe networking is not up and running properly at the time gpsd is started? Since it needs to start listening on port 2947 networking MUST be going, and it might not have finalized yet?
Bo Berglund
Sweden

quinness
Posts: 17
Joined: Thu Mar 10, 2016 12:02 pm

Re: Running script to start daemon at boot on Jessie

Thu Mar 10, 2016 9:39 pm

Hallo again. Have you tested just to start a software that need gpsd?

Code: Select all

pi@raspberrypi:~ $ ps -aux | head -1 ; ps -aux | grep gps | grep -v grep
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pi@raspberrypi:~ $ xgps
pi@raspberrypi:~ $ ps -aux | head -1 ; ps -aux | grep gps | grep -v grep
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
gpsd       722 22.5  1.7  22108  7872 ?        S<sl 21:35   0:04 /usr/sbin/gpsd -N -b -N -D 3 /dev/ttyUSB0 -n -F /var/run/gpsd.sock /dev/ttyUSB0
pi@raspberrypi:~ $
My starts automatically when a software like xgps needs it

Edit: May be intersting with dmesg

Code: Select all

[  104.837578] pps_core: LinuxPPS API ver. 1 registered
[  104.837609] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[  104.845896] pps_ldisc: PPS line discipline registered
[  104.849485] pps pps0: new PPS source usbserial0
[  104.849836] pps pps0: source "/dev/ttyUSB0" added
/Edit:
/Johan C. Sweden
Raspian Jessie 2016-02-26 _-=* If there are choices, why complain? *=-_
openSUSE LEAP 42.1 (3 pcs) _-=* Uppland, Sweden *=-_

Return to “Raspberry Pi OS”