Two ideas:
First, execute the monitoring script regularly
Use the crontab that comes with centos to execute the status.sh script regularly as needed.
#!/bin/bash
status=$(ps -aux | grep “rsync –daemon” | grep -v “grep” | wc -l)
if [ $status -eq 0 ];then em>
systemctl restart rsyncd.service
else
exit 0;
fi
Second, the way of background execution
sh status.sh &
#!/bin/bash
while true
do
ps -aux | grep “rsync –daemon” | grep -v “grep” | wc -l
if [$? -ne 0 ]; then
systemctl restart rsyncd.service
fi
sleep 10
done
The current general idea is these two Kind, if you have other ideas, please leave a message to discuss!