Ad Widget

Collapse

Executing Script when zabbix-server,service is down

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vussey
    Junior Member
    • May 2022
    • 6

    #1

    Executing Script when zabbix-server,service is down

    Hello everyone,

    I would like to know if it's possible to somehow start a shell/python script on a server when its zabbix-server.service is currently down or disabled.
    If itry to launch a script i receive following message, which is obviously because of the down zabbix-server.service

    Click image for larger version

Name:	Screenshot 2023-08-01 154357.png
Views:	431
Size:	31.6 KB
ID:	468104


    The case would be for a passive zabbix server to manually start a script which restarts or starts the zabbix-server script.
    The passive Server is periodically getting its DB replaced by another zabbix server with a basic script containing a SQLdump.
    These 2 Servers are independed from each other, not configured as HA and seperated by quite a distance.

    I tried tinkering with some custom php file which should enable the service once it is launched by a button containing the custom file,
    if you have any better advice, feel free to reach out !

    Thanks and best regards
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Systemd provides some options that will help you configure if a service should be restarted in the event of a failure. Read on to find out more

    Comment

    • Vermizz
      Member
      • Oct 2022
      • 33

      #3
      You can also write a script that checks if the service is running and put it in​ cron.

      Script example:
      Code:
      #!/bin/bash
      # Check zabbix-server is running
      if systemctl is-active --quiet zabbix-server.service; then
          echo "zabbix-server service is running."
      else
          # service is not running, start it
          sudo systemctl start zabbix-server.service
          if [ $? -eq 0 ]; then
              echo "The zabbix-server started successfully."
          else
              echo "The zabbix-server not started, check log"
          fi
      fi
      ​

      Comment

      Working...