-- PaulGrenz - 21 Sep 2020

Starting, stopping and controlling INDI Drivers

As mentioned previously, the "indiserver" manages all the INDI drivers. They should not be started or stopped directly, but by using a "killall" to end the process and allowing the "runindi" script to respawn the process:

killall driver1

The way this works is that a script in "/etc/rc.local" is run on boot, and in this script is a call to the "runindi" script:

# start INDI
/opt/local/lbti/scripts/runindi >> /opt/local/lbti/logs/run.log 2>&1 &

This will also take any output from this script and log it to the "run.log" file. This is useful in dertermining what, if any errors accurred managing all the INDI drivers. This script will look something like this:

#!/bin/sh
# !!!! DO NO EDIT THIS FILE! IT IS AUTOMATICALLY GENERATED BY 'buildall -i' !!!!
 
# Set base of INDI software installation:
export INDI_INSTALL=/opt/local/lbti
# Minimal PATH:
export PATH=/bin:/usr/bin:/opt/local/lbti/bin:/opt/local/lbti/scripts
# Directory for cores:
cd /opt/local/lbti/cores
ulimit -c unlimited
# Log dir:
INDI_LOG_DIR=/opt/local/lbti/logs/is
# Define the flag file name:
INDI_FLAG_FILE=/tmp/noindi
 
DRIVERS="
driver1
driver2
driver3
"
# Define a number of seconds in between checks.
SLEEP_TIME=2
# Define the port that the indiserver will use. The default is 7624.
IS_PORT=7624
 
# Forever:
while [ 1 ]; do
if [ -r $INDI_FLAG_FILE ]; then
echo "Sleeping $SLEEP_TIME seconds because $INDI_FLAG_FILE exists."
echo "Remove $INDI_FLAG_FILE to start indiserver."
else
# indiserver
if ! killall -qs 0 indiserver; then
echo ""; date -u; echo "Starting indiserver"
indiserver -p $IS_PORT -m 200 -v -l $INDI_INSTALL/logs/is $DRIVERS &
fi
fi
sleep $SLEEP_TIME
done

As stated, this file is auto-generated by the build script and contains the list of drivers that the indiserver should manage. Since there is no PATH variable or ".bashrc" to set the install directory, these two things are set here. A "cores" directory is also set to capture crashes for debugging later, as is a log file for the indiserver. This log file will contain indiserver messages, and any messages written to stderr by any driver, since the indiserver manages stdin, stdout, and stderr (see the previous articles for an in-depth explanation about the indiserver).

The main "forever" loop ensures that the indserver will be restarted if it is stopped or crashes. The expression "killall -qs 0 indiserver" checks to see if there is a pid associated with it, and if not, restarts it running on the correct port. It is given the list of drivers to manage, and if they are not running, starts each in turn. In this way, the system will self-heal if it fails in some way. This indicates that drivers should be able to be restarted without consequences, and in effect be stateless or read their state directly from the hardware they are talking to.

Another feature of this script is related to the presence of a "noindi" file. Each time through the loop, if this file exists (it's ok if its empty) INDI drivers will not be restarted if they have been stopped or crashed. This is useful for debugging or keeping the system from running at all.

To stop the system:

touch /tmp/noindi
sudo pkill indiserver

The "touch" will create the noindi file and prevent things from restarting. The "pkill" will stop the indiserver, and since all the INDI drivers are child processes of it, they will be stopped too.

To restart everything, just remove the file:

rm -f /tmp/noindi

The indiserver will restart in a few seconds and then start all the drivers as well.
Topic revision: r3 - 25 Sep 2020, PaulGrenz
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback