Load on start up?

433 views
Skip to first unread message

Marlin

unread,
Jul 10, 2017, 12:07:06 PM7/10/17
to kplex
New to Kplex and Raspberri Pi.

I have it working with the dAISy AIS receiver, it works great.

After restarting I have to run these commands:
sudo service kplex start
sudo kplex file:direction=out

What is the best way to automate this so it starts automatically on reboot?

I follow the configuration documentation and it should be starting on its own but it is not.


Keith Young

unread,
Jul 16, 2017, 4:01:59 PM7/16/17
to kplex

Apologies for the delay in reply: been sailing.

See the section "Invocation at boot time" on the install page:
http://www.stripydog.com/kplex/kplex.html

If that doesn't work let me know: It's possible that systemd in a recent raspbian isn't respecting legacy init files

You need to have configured the configuration file (ie /etc/kplex.conf)

Marlin

unread,
Mar 23, 2018, 8:57:18 AM3/23/18
to kplex
Thanks Keith,

I'm running this on a Raspberry Pi I'm using as an AIS receiver. I have followed the documentation but cannot get Kplex to run on start up.

I've tried this:

Created a file called aisstart.sh in  /home/pi

Inside the file it says

sudo service kplex start

sudo kplex file:direction=out

Then

chmod -755 /home/pi/aisstart.sh

 

And added it to rc.local with and without bash

bash /home/pi/aisstart.sh &

#!/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.

exit 0

I can run the script and rc.local manually but it will not run at start up.


When that didn't work I removed it from rc.local and added it as a cron job using:


@reboot sleep 10 cd/home/pi && /bin/bash aisstart.sh


With and without the sleep.

 

Is there something simple I am missing or a better way?

Keith Young

unread,
Mar 25, 2018, 10:53:26 AM3/25/18
to kplex

Is there something simple I am missing or a better way?


There's a number of things wrong here.  In reverse order....

I think you're adding invocation of your script before the #! line in rc.local. Don't do that.  That's a magic string which needs to be at the top of a script to tell linux how to run it (in this case using /bin/sh). Anything you want to add to this should go after the #! line and before the "exit" statement.  But there are better ways to do this on startup.  And they don't involve cron.

Also...your script necessarily do what you think it will. If kplex is registered as a service, the first line would start it.  But then you're trying to invoke it again, this time directly, and in the foreground, so your script won't exit until kplex dies, which is definitely not what you want in a startup script.

The instructions on the web site I previously pointed you at which uses update-rc.d should have enabled the kplex service using "legacy" init scripts.  I'm surprised that didn't work, even for a recent raspbian (assuming you're running raspbian).  What happens if you run:
find /etc/rc.d -name "*kplex*"

Of course I've been assuming that you installed kplex from deb...you do have /etc/init.d/kplex installed?  If not, install that (copy from the kplex.init in the sources you used to compile kplex) and repeating the earlier steps with update-rc.d may be more successful. Alternatively... 

The next release of kplex has a systemd service file but that references a kplex option which is not available in earlier releases.  I've uploaded an edited (and, caveat, untested) service file which should be good for the current release:
The raspbian documentation on how to install and use a systemd service file is here:

Essentially you need to make sure kplex is not running, download the service file, copy it to /lib/systemd/system, start kplex using:
sudo systemctl start kplex.service
check it's running and if you're happy it is enable the service to start on boot with:
sudo systemctl enable kplex.service

Arthur Lamiral

unread,
Mar 26, 2018, 10:51:45 AM3/26/18
to kplex
Bonjour,

Le meilleur moyen d'automatiser Kplex au démarrage est de créer un service dans l'environnement de SystemD puisque celui-ci devient incontournable dans les distributions Raspbian postérieure à Jessie.
Mon objectif personnel est de démarrer Kplex quelques soient les circonstances sur le Raspberry jusqu'à ce que le GPS ( Garmin ) soit opérationnel, ce qui prends un peu de temps. Ma solution ne prétend surtout pas résoudre tous les problèmes, mais sur ma machine elle fonctionne, et je vous la livre telle qu'elle :

En scrutant le script kplex de rc.d, j'ai créer un fichier kplex.service pour l'intègrer à SystemD :

# kplex.service  Largement inspire by systemd-sysv-generator

[Unit]
Description= Kplex NMEA 0183 multiplexer
Documentation = http://www.stripydog.com/kplex/configuration.html
ConditionFileIsExecutable=/usr/bin/kplex
ConditionFileNotEmpty=/etc/kplex.conf
Before=multi-user.target
After=syslog.target network.target audit.service
Wants=network-online.target

[Service]
Type=forking
Restart=on-failure
RestartSec=60
User=root
Group=dialout
IgnoreSIGPIPE=no
KillMode=process
PIDFile=/run/kplex.pid
ExecStart=/usr/bin/kplex -f /etc/kplex.conf -o mode=background
ExecStop=/usr/bin/pkill -9 kplex
ExecReload=/usr/bin/pkill -1 kplex

[Install]
WantedBy=multi-user.target
# fin de fichier

j'ai invalidé la configuration existante
    sudo systemctl stop kplex.service
    sudo systemctl disable kplex.service

j'ai copier mon fichier dans
    /etc/systemd/system/kplex.service

J'ai validé la nouvelle configuration
    sudo systemctl daemon-reload
    sudo systemctl enable kplex.service
    sudo reboot ou bien sudo systemctl start kplex.service

C'est fini ...
Cordialement.
Arthur

Arthur Lamiral

unread,
Apr 14, 2018, 5:50:54 AM4/14/18
to kplex

Bonjour,

un complément à ma procédure pour éviter les télescopage entre SystemD et SysVinit

# kplex.service  Largement inspire by systemd-sysv-generator

[Unit]
Description= Kplex NMEA 0183 multiplexer
Documentation = http://www.stripydog.com/kplex/configuration.html
ConditionFileIsExecutable=/usr/bin/kplex
ConditionFileNotEmpty=/etc/kplex.conf
Before=multi-user.target
After=syslog.target network.target audit.service
Wants=network-online.target

[Service]
Type=forking
Restart=on-failure
RestartSec=60
User=root
Group=dialout
IgnoreSIGPIPE=no
KillMode=process
PIDFile=/run/kplex.pid
ExecStart=/usr/bin/kplex -f /etc/kplex.conf -o mode=background
ExecStop=/usr/bin/pkill -9 kplex                                                # Merci à Keith
ExecReload=/usr/bin/pkill -1 kplex                                             # de placer les bonnes commandes ici

[Install]
WantedBy=multi-user.target
# fin de fichier

j'ai invalidé la configuration existante
    sudo systemctl stop kplex.service
    sudo systemctl disable kplex.service
    sudo update-rc.d -f kplex remove
    sudo mv /etc/init.d/kplex /home/pi/kplex  # on le met dans le frigidaire, on ne sait jamais ...

j'ai copier mon fichier dans
    /etc/systemd/system/kplex.service

J'ai validé la nouvelle configuration
    sudo systemctl daemon-reload
    sudo systemctl enable kplex.service
    sudo reboot ou bien sudo systemctl start kplex.service

C'est fini ...
Cordialement.
Arthur
Le lundi 10 juillet 2017 18:07:06 UTC+2, Marlin a écrit :

Keith Young

unread,
Apr 14, 2018, 11:22:09 AM4/14/18
to kplex

ExecStop=/usr/bin/pkill -9 kplex                                                # Merci à Keith
ExecReload=/usr/bin/pkill -1 kplex                                             # de placer les bonnes commandes ici


Est-ce q'on dit "tuer un processus" en français?

Dans les plupart des cas c'est préférable de tuer kplex  avec SIGTERM (ie kill  sans options ou "kill -TERM").  Avec SIGTERM, kplex attend que toutes interfaces envoient leur data (comment on dit "buffered"?  tamponné?) et restaurent leur paramètres précédents (baud pour les interfaces serial par example).  Si on l'envoie SIGKILL kplex ne peut pas faire ça.  Aussi, kplex n'attrape pas SIGHUP, donc pkill -1 termine le processus inélégamment.  Attraper SIGHUP pour relire la configuration est une fonctionnalité que je veux ajouter.

Keith Young

unread,
Apr 14, 2018, 11:24:20 AM4/14/18
to kplex
I still don't know why legacy init scripts aren't working with systemd-based raspbian.  I'll need to investigate a with a newer distribution than the one on my pi

Arthur Lamiral

unread,
Apr 15, 2018, 11:51:09 AM4/15/18
to kplex
Bonjour Keith,

On tue allègrement et dans la bonne humeur les processus en français ...

Ce que j'ai compris de SystemD :
Moteur SystemD + fichier Appli.service = script dans /etc/init.d/
Pour un fonctionnement harmonieux de SystemD
Les concepteurs de logiciels placent leur fichiers d'instructions dans /lib/systemd/system/
Les utilisateurs personnalisent leurs machines avec /etc/systemd/system/ qui est lu en dernier.

SAUF QUE

Pour des raisons de compatibilité antérieur, SystemD analyse les contenus des rc*.d, et si il trouve des scripts existants dans /etc/init.d/ et activés dans rc*.d,
il essaye de construire un Appli.service par lui-même et le place dans /run/systemd/generator.late/ pour l'interprèter ensuite selon la cible *.target qui ressemble le plus
a un RunLevel connu avant. Ceci avec des approximations plus ou moins larges ...

C'est pourquoi il est important de désactiver tous les vieux composants de SysVinit, voir des les supprimer,
si on veut travailler efficacement avec SystemD.

Pour la petite histoire, c'est en piochant un kplex.service dans /run/systemd/generator.late/
et en le comparant avec les instructions du script kplex dans /etc/init.d d'une installation d'origine
que j'ai construit le kplex.service que je livre à votre sagacité ...

Merci de votre indulgence pour les erreurs que vous allez y trouver ...

Cordialement.
Arthur

Newcastle Lifeboat

unread,
Jun 1, 2018, 7:14:32 AM6/1/18
to kplex
Hi Kieth..

Did you every sus out why the scripts won't run on the newer versions of Raspbian? I've also tried a number of ways and can't figure it out.

What is the newer version of kplex like?

Regards

Declan


On Saturday, April 14, 2018 at 4:24:20 PM UTC+1, Keith Young wrote:

James Brown

unread,
Jun 2, 2018, 12:23:22 PM6/2/18
to kplex
HI Keith

Been using kplex for some time now, but recently obtained a Pi 3 and with the new version of Raspbian I could get it all configured but could not get it to run on boot.  I could make it work by manually starting with "sudo service kplex start".  But as I want this installation to work without keyboard or screen this was not an option!

To cut a long story short I have tried the kplex.service suggestions above, but still the same end result. I have tried to get scripts to run at startup to call sudo service kplex start but that fails too

James

Henk van Heuveln

unread,
Jun 2, 2018, 12:59:01 PM6/2/18
to James Brown, kplex
James.
Try to run it in debug mode and see why it stop.
Sudo kplex -d9





Sent from my Bell Samsung device over Canada's largest network.
--
You received this message because you are subscribed to the Google Groups "kplex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kplex+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kplex/93fbcf92-13ea-4b49-a107-138122f3304b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Teppo Kurki

unread,
Jun 2, 2018, 1:00:30 PM6/2/18
to kplex
With systemd you should create a unit file and enable the service. Have you looked into doing that?


--

Julian Cable

unread,
Jun 2, 2018, 1:17:44 PM6/2/18
to Newcastle Lifeboat, kplex

I've got kplex auto starting on the latest raspbian on a pi3. I've also added a systemd service to create some symlinks I couldn't do in udev for USB serial devices. If I can get my laptop charged I'll share them.

--
You received this message because you are subscribed to the Google Groups "kplex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kplex+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kplex/9b0af5d2-919c-4a13-9a9a-dea450b3ab0c%40googlegroups.com.

Keith Young

unread,
Jun 2, 2018, 1:21:50 PM6/2/18
to kplex


Did you every sus out why the scripts won't run on the newer versions of Raspbian? I've also tried a number of ways and can't figure it out.

Last month I tested on the latest stretch-based raspbian.  "Legacy" startup (ie sysv init scripts) worked fine.  What I'm guessing is happening is an ordering thing.  kplex is maybe starting before one of the devices it requires is available.  A unit file is not necessarily going to help unless it has the correct dependencies.

What would help here would be if people experiencing this problem could try editing their init script to stick -d3 onto the kplex invocation line.  When it fails on startup, check the messages file.  I suspect you'll see an error about a device not being available.  If that's correct we can take it form there.

The long promised persist=fromstart option for serial interfaces would of course help us here but that still isn't trivial.

Henk van Heuveln

unread,
Jun 2, 2018, 1:32:17 PM6/2/18
to kp...@googlegroups.com

I'm using it on the latest version Jessie and Pi3 B+ and it is working normal

Henk

--
You received this message because you are subscribed to the Google Groups "kplex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kplex+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kplex/839580d8-ee37-4117-8aa0-5d05d187a05b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

Henk van Heuveln

Owner | Service Technician
+1 (902) 229 0858 | he...@seacoastmarine.ca

Seacoast Marine Electronics Ltd.
102 Chain Lake Drive, Unit 5 | Halifax, NS | B3S 1A7

Check out our website at:
www.seacoastmarine.ca

James Brown

unread,
Jun 2, 2018, 1:48:39 PM6/2/18
to kplex
So to clarify Kplex works as a service so long as it is not invoked at boot up.
I cheated and in Raspi--config asked it to go straight to the desktop and added a line to the autostart file in the LXDE-pi folder, which called a script to start kplex as a service.

However when playing with the system files the error message I think was along the lines of "no resources".  It does sound to me as if it is trying to start before the devices are available.  As I have a number of USB devices I use Udev to give them sensible names.  Unfortunately whilst I have years of Windows/DOS experience I am a bit of a newbie with Linux.  Keith, I just want to be clear here, I am adding the -D3 switch is in the kplex.service file or the kplex file in the init.d directory?

James

Newcastle Lifeboat

unread,
Jun 4, 2018, 4:48:49 AM6/4/18
to kplex
Strangely enough, I just did a clean install on a Raspberry Pi 2 with the latest version of Raspian. I've installed kplex and updated the config file to my settings. I also installed telnet and tcpdump to view outputs and all appears to be working fine. The kplex NMEA 0183 Multiplexer shows up as loaded and it's receiving AIS data. Weird!

Declan

Steve Smith

unread,
Feb 2, 2020, 1:06:59 PM2/2/20
to kplex
Hi - I apologize for posting here - if the issues is resolved elsewhere can you please point me in the right direction?

I just bought a pi B and a dAISy HAT and have gotten them running an am using kplex to send the AIS messages to my router. My iPad running Aqua Maps is picking them up from there. All good, thanks very much for this software. The only issue sis the one that you all were talking about - the kplex service does not start up wnen I reboot the pi. I am a pi noob so I am also confused about the -D3 suggestion and where to add it an also where to find the messages.

thanks in advance for your help.
Message has been deleted

Steve Smith

unread,
Feb 3, 2020, 7:30:50 PM2/3/20
to kplex
I ended up writing a script called start_kplex.sh
The script sleeps for 10 seconds before trying to start the kplex service in order to let all of the other services that it might depend on start first

  #!/bin/bash
  sleep 10
  sudo service kplex start

then I set up a chron job

Use this to bring up the chron job editor
  crontab -e

then add a line
  @reboot /home/pi/start_kplex.sh

this runs the above script at reboot.

it seems to work

Keith Young

unread,
Feb 5, 2020, 4:26:40 AM2/5/20
to kplex

Sorry for the late reply.

Assuming you installed from a .deb, did you do:
sudo update-rc.d kplex defaults

Which is the "normal" mechanism for startup on boot?  In this thread some people were raising the issue that on some newer distributions this is not placing kplex start-up at the appropriate place in the boot sequence after all devices have come on line althought his does not seem to be such an issue with fresh installs.

If you didn't do the above give it a go.  If it doesn't work we can go through use of the unit file for startup.

I haven't devoted time to this recently but should have a little more time on my hands for open source work from next month


Steve Smith

unread,
Feb 7, 2020, 11:12:29 AM2/7/20
to kplex
Hi - Yes, I did do that. I am running on a Raspberry Pi. I did not see a file called rc.d, however there is one called rc.local. Is it possible that I should have used rc.local in the command instead?

Keith Young

unread,
Feb 10, 2020, 8:14:39 AM2/10/20
to kplex



Hi - Yes, I did do that. I am running on a Raspberry Pi. I did not see a file called rc.d, however there is one called rc.local. Is it possible that I should have used rc.local in the command instead?

"/usr/sbin/update-rc.d"  is a command for manipulating old-style startup commands and is part of the init-system-helpers package.  It's function is to manipulated the links in the /etc/rc[0-9].d directories which get run at startup/shutdown

James Brown

unread,
Mar 9, 2020, 7:48:47 PM3/9/20
to kplex
I am still struggling! I cannot make kplex start on boot.  Its fine if ask it to restart after boot.
However I have discovered that asking for service status gives me the following.  So it looks like something to do with creating the TCP interface.

Any suggestions how to fix it please?  I have tried every version of shell scripts to no avail.

Many thanks

James

pi@raspberrypi3:~ $ sudo systemctl status kplex
● kplex.service - LSB: Start kplex NMEA 0183 multiplexer
   Loaded: loaded (/etc/init.d/kplex; generated; vendor preset: enabled)
   Active: active (exited) since Mon 2020-03-09 22:34:49 GMT; 2min 41s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 463 ExecStart=/etc/init.d/kplex start (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/kplex.service
Mar 09 22:34:48 raspberrypi3 systemd[1]: Starting LSB: Start kplex NMEA 0183 multiplexer...
Mar 09 22:34:49 raspberrypi3 kplex[463]: Starting kplex multiplexer: kplex.
Mar 09 22:34:49 raspberrypi3 systemd[1]: Started LSB: Start kplex NMEA 0183 multiplexer.
Mar 09 22:34:49 raspberrypi3 kplex[463]: Failed to open tcp server for 192.168.1.155/10110: Cannot assign requested address
Mar 09 22:34:49 raspberrypi3 kplex[463]: Failed to initialize Interface _tcp-id4



Keith Young

unread,
Mar 11, 2020, 4:31:03 AM3/11/20
to kplex

Any suggestions how to fix it please?  I have tried every version of shell scripts to no avail.

My guess is the network is, for whatever reason, not being brought up before kplex starts.  As a look through other people's posts here will confirm, it's long overdue that I stopped ignoring systemd on Linux and switched to using unit files for startup.

Try this:
* kill kplex
sudo service kplex stop
* Move its init file aside:
sudo mv /etc/init.d/kplex /etc/init.d/kplex.back
* Remove the sysV startup links:
sudo update-rc.d kplex remove
* link in the kplex unit file:
sudo ln -s /usr/share/kplex/kplex.service /etc/systemd/system/
* enable it:
sudo systemctl enable kplex
* Reboot and see if it's working

If it works let me know and going forwards I'll switch to systemd as the default for debs

James Brown

unread,
Mar 12, 2020, 4:43:19 PM3/12/20
to kplex
Hi I tried that but unfortunately I am not able to offer diagnostic information.  I got to the last step and it failed, I did not note the error message (sorry) as I was going to come back to it.  Unfortunately the SD card subsequently died and I have had to rebuild everything from scratch.

Good news Kplex works like a charm!

Bad news is I cant install CPN from the packages and am having to build it on the pi.

James

James Brown

unread,
Mar 12, 2020, 4:44:03 PM3/12/20
to kplex
PS Sorry I cant offer more information, but I do greatly appreciate your help.  J

James Brown

unread,
Apr 26, 2020, 7:56:06 AM4/26/20
to kplex
So I have a solution.  I am afraid it is very dirty.  Sorry

I noticed that kplex was not being allowed to create the network connections and as you thought before that things were not being done in the correct order/at the correct time when other services were ready (see service status).

So my very dirty solution was to add a sleep(10) in the first line of the main loop in kplex.c.

This seems to allow enough time for everything else to get appropriately configured.

Apologies again for such a dirty solution

James


pi@raspberrypi3plus:~ $ service kplex status

● kplex.service - LSB: Start kplex NMEA 0183 multiplexer
   Loaded: loaded (/etc/init.d/kplex; generated)
   Active: active (running) since Sun 2020-04-26 12:47:23 BST; 58s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 424 ExecStart=/etc/init.d/kplex start (code=exited, status=0/SUCCESS)
    Tasks: 7 (limit: 2200)
   Memory: 1.1M
   CGroup: /system.slice/kplex.service
           └─709 /usr/bin/kplex -f /etc/kplex.conf -p /var/run/kplex.pid -o mode background
Apr 26 12:47:18 raspberrypi3plus systemd[1]: Starting LSB: Start kplex NMEA 0183 multiplexer...
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Starting kplex multiplexer: kplex.
Apr 26 12:47:23 raspberrypi3plus systemd[1]: Started LSB: Start kplex NMEA 0183 multiplexer.
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Could not stat /dev/ttyUSB4: No such file or directory
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Failed to initialize Interface _serial-id5
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Failed to open tcp server for 192.168.1.119/10110: Cannot assign requested address
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Failed to initialize Interface _tcp-id6
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Failed to open tcp server for 192.168.3.1/10110: Cannot assign requested address
Apr 26 12:47:23 raspberrypi3plus kplex[424]: Failed to initialize Interface _tcp-id7

Message has been deleted

Jakob Thur

unread,
Apr 24, 2022, 10:18:45 AM4/24/22
to kplex

A belated thank you  Keith for the March 11, 2020  fix which appear to have solved a multiyear battle with the kplex startup after reboot on my Raspberry AIS receiver. Over time I mitigated using cron with a 30 sec delay on kplexstartup,  (I never used    sudo update-rc.d kplex defaults   )

 

@reboot /bin/sleep 30 ; /usr/bin/kplexstartup > / home/pi/crontablog.log

     

I never understood      crontab -e     vs      sudo crontab -e    so I used both every time to be sure) -  and this mitigation  still worked on my Stretch-to-Bullseye upgraded SD card until now. 

 

But my decision to move the upgraded Stretch-to-Bullseye to a USB Flash configuration turned out to be unsuccessful so I made a new AIS receiver from scratch on a fresh Bullseye on Flash USB, only to find that kplex would no longer start after boot, not even after a 180 sec cron delay.

 

But now with your fix below  kplex starts up after reboot, without the crontabs.

 

* kill kplex

sudo service kplex stop

* Move its init file aside:

sudo mv /etc/init.d/kplex /etc/init.d/kplex.back

* Remove the sysV startup links:

sudo update-rc.d kplex remove

* link in the kplex unit file:

sudo ln -s /usr/share/kplex/kplex.service /etc/systemd/system/

* enable it:

sudo systemctl enable kplex

* Reboot 

 

Thanks Keith also for your follow-up on other KPLEX configuration issues

Reply all
Reply to author
Forward
0 new messages