I have an script that restarts Solr which I run from cron.:
./restartsolr.sh
systemctl stop solr
systemctl start solr
How can I add a test to only stop & start solr if solr status is inactive.
Running service solr status when stopped gives:
solr.service - LSB: Controls Apache Solr as a Service
Loaded: loaded (/etc/init.d/solr; generated)
Active: inactive (dead) since Fri 2022-07-08 16:52:14 UTC; 1min 55s ago
Docs: man:systemd-sysv-generator(8)
Process: 16432 ExecStart=/etc/init.d/solr start (code=exited, status=0/SUCCESS)
Process: 16671 ExecStop=/etc/init.d/solr stop (code=exited, status=0/SUCCESS)
So using bash can I write something like
solr_status = service solr status
if solrstatus.include "dead"
systemctl stop solr
systemctl start solr
end
What would the syntax be in bash for that? Is this the best way / an ok way to monitor solr ?
If you really want to check that solr is not active then you can do this result=$(systemctl is-active solr) if [[ $result != active ]]; then systemctl start solr; fi
result=$(systemctl is-active solr) if [[ $result != active ]]; then systemctl start solr; fi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.