Automatic start by using systemd: Difference between revisions
| (3 intermediate revisions by the same user not shown) | |||
| Line 27: | Line 27: | ||
After=multi-user.target | After=multi-user.target | ||
After=network-online.target time-sync.target | After=network-online.target time-sync.target | ||
Wants=network-online.target time-sync.target | Wants=network-online.target time-sync.target | ||
| Line 47: | Line 46: | ||
For starting the control application manually via systemd, one can use the command <code>sudo systemctl start aquarium_control_startup.sh</code>. | For starting the control application manually via systemd, one can use the command <code>sudo systemctl start aquarium_control_startup.sh</code>. | ||
Note: Waiting for the NTP before starting the application will avoid a wrong timestamp occurring, but may inhibit the start of the application if the internet connectivity is gone. | |||
== Creating message queues for operation or test of aquarium_control == | == Creating message queues for operation or test of aquarium_control == | ||
Latest revision as of 19:50, 17 February 2026
Content of the startup script
The shell script for startup of the control application (/usr/local/bin/aquarium_control_startup) has the following content:
echo 0 > /var/local/aquarium-ctrl.pid
sudo touch /dev/mqueue/aquarium_control.6UXp
chmod o+rwx /dev/mqueue/aquarium_control.6UXp
/usr/local/bin/aquarium_control > /dev/null&
It resets any PID in the lock file from previously instances which were potentially not shut down correctly (for example, in case of power failure). It creates the message queue file which is not a file on the hard drive and sets permission accordingly. Finally, it starts the control application in the background.
Configuration of automatic start
The content of systemd unit file /lib/systemd/system/aquarium_control.service as following:
[Unit]
Description=Aquarium Control Application
After=multi-user.target
After=network-online.target time-sync.target
Wants=network-online.target time-sync.target
[Service]
Type=forking
ExecStart=bash /usr/local/bin/aquarium_control_startup
[Install]
WantedBy=multi-user.target
Upon creation/modification of the unit file, one must run the command sudo systemctl daemon-reload in order to activate the changes.
For starting the control application manually via systemd, one can use the command sudo systemctl start aquarium_control_startup.sh.
Note: Waiting for the NTP before starting the application will avoid a wrong timestamp occurring, but may inhibit the start of the application if the internet connectivity is gone.
Creating message queues for operation or test of aquarium_control
The startup script contains the creation of a set of message queues:
sudo touch /dev/mqueue/aquarium_control.5UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.5UXp
sudo touch /dev/mqueue/aquarium_control.4UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.4UXp
sudo touch /dev/mqueue/aquarium_control.6UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.6UXp
sudo touch /dev/mqueue/aquarium_control.7UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.7UXp
sudo touch /dev/mqueue/aquarium_control.8UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.8UXp
sudo touch /dev/mqueue/aquarium_control.9UXp
sudo chmod o+rwx /dev/mqueue/aquarium_control.9UXp
Only one of the message queues is required for operating the control application. The other message queues are use for parallel SW unit testing.
Initialize lock file with zero as PID
The startup script contains the following command:
sudo echo 0 > /var/local/aquarium-ctrl.pid
The lock file has to be initialised to contain zero upon restart of the server. A missing or empty lock file is interpreted by the control application that something has gone wrong and startup will be aborted. In case of uncontrolled shutdown (e.g. power failure), the PID of the last operation may still be in the lock file, hence a reset to zero is required for this case.
Start the application to run in the background
The start of the application in the background is triggered with the following command:
/usr/local/bin/aquarium_control > /dev/null&