How can I execute dedicated commands as part of the boot process?

Create or edit the file /etc/rc.local and add the corresponding commands. An example using the vim editor.

sudo vim /etc/rc.local
chmod 755 /etc/rc.local

After a reboot, the Redis cache should be emptied and the Neos node index created:

#!/bin/sh

/usr/local/bin/redis-cli flushall
/usr/bin/su -m proserver -c "FLOW_CONTEXT=Production/Live /usr/local/bin/php /var/www/neos/flow nodeindex:build --workspace live"

Please note that the paths to the executable programs are specified in absolute terms.

Why is this necessary?

Some applications do not work completely after a reboot. This is often due to invalid cache content. Which caches need to be emptied is of course application-specific.

Reboots are necessary, for example, as part of the punkt.de infrastructure patch days in order to provide updated system packages.