Service start and stop sequence on init.d
-
Hi,
Product in use: Onion Omega 2+ (with custom hardware)
Firmware in use: 0.2.2 b202
Description: We have created a service to start/stop/restart our solution on init.d with the sequence configuration START=90 and STOP=10. What the sequence configuration you suggest for the START and STOP? Our solution is a completed solution that uses almost all the services existents (3G, NTPD, GPIO, etc.).Thank you in advance.
-
@francisco-vieira Starting and stopping services on any *nix platform needs to be done in a methodical way. Start and Stop need to be considered separately.
Start numeric sequence should be decided based upon dependencies on other services and often you may need to consider the time each of these dependent services may take to start. For example, a service that depends upon Mosquitto (MQTT) will need to start after Mosquitto, but also consider that Mosquitto is a bit a dog in getting itself up and ready to serve, so unless your service can deal with this delay, you may want to start your service further down the start list in order to ensure Mosquitto has started.
Similarly, Stop should consider that it should close any connections to other services before those services terminate, and that sequence should inform your stop value.
Testing the sequence should also consider if a dependency may stop and start post boot and if such a scenario creates a further start/stop dependency.
-
Thank you for all your help on this clarification @crispyoz. But maybe the most fail safe way to guarantee all the needed services are up is to put my service on the last position of START?
-
@francisco-vieira That may be a solution but it may not work reliably. If your service is dependent on 1 or more other services being up and running, you need to be able to reliably confirm they are in fact up and running. To complicate the issue, some applications may technically complete startup but they may spawn other threads to listen or publish and these may not complete startup at the same time.
My experience is that if I develop a service that has dependencies on other services, I add logic to my services' startup code to check it can connect to the required resources or services and manage any delays in those dependencies.
-
@crispyoz thank you so much for your suggestion. I think we will follow your suggestion and add some logic on our service to guarantee all the required resources/services are up before we start our service.
Thank you so much my friend.