I've been using Systemd for a while in Debian 8. I use the Restart=on-failure option to waken-up a service in case of failure.
I will like to know if there is a way to force the restart of the service if it is not listening to a specific port (even if the process stills running).
The reason of why I need that is because we are developing the new feature to will fix this issue but it will require a while. Meanwhile we need a workaround.
I have developed a script to check that status:
#! /bin/bash
PORTS=( 1452 542 )
for port in ${PORTS[@]}; do
netstat -anp | grep $port > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
# Port blocked. Kill the running process and start it again after a while
done
This script is triggered periodically using the cron.I know it is a dirty trick. That's why I would like to integrate that behaviour in Systemd checking. Is that possible?
Thank you in advance.
Cheers,
A.