Ad Widget

Collapse

Upstart Script for zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scanch
    Junior Member
    • Oct 2010
    • 8

    #1

    Upstart Script for zabbix

    Hello,

    Here are simple upstart scripts (tested under ubuntu 10.04.1 server) for zabbix-server and zabbix-agent.
    Any feedback & suggestions are welcomed.

    zabbix-agent.conf:
    Code:
    # zabbix-agent - Start zabbix agent
    description     "Zabbix Agent"
    author          "S. CANCHON"
    start on runlevel [2345]
    stop on runlevel [016]
    respawn
    expect daemon
    exec /usr/sbin/zabbix_agentd
    zabbix-server.conf:
    Code:
    # zabbix-server - Start zabbix server
    description     "Zabbix Server"
    author          "S. CANCHON"
    start on (runlevel [2345]
              and started mysql)
    stop on runlevel [016]
    respawn
    expect daemon
    exec /usr/sbin/zabbix_server
    Just have to copy them in /etc/init/ and control them with upstart tools.
    Last edited by scanch; 28-10-2010, 20:04.
  • sYB-tyumen
    Junior Member
    • May 2010
    • 4

    #2
    Additional section for those, who store pid files not in the default directory

    I store zabbix pid files in /var/run/zabbix. So i added
    Code:
    pre-start script
      if [ ! -d /var/run/zabbix ]; then
            mkdir -p /var/run/zabbix
        chown zabbix:zabbix /var/run/zabbix
        chmod 755 /var/run/zabbix
      fi
    end script
    between "respawn" and "expect daemon"

    Comment

    • richlv
      Senior Member
      Zabbix Certified Trainer
      Zabbix Certified SpecialistZabbix Certified Professional
      • Oct 2005
      • 3112

      #3
      pretty simple indeed
      would it be ok to add these to the zabbix distribution, in case they are useful for somebody else ?
      Zabbix 3.0 Network Monitoring book

      Comment

      • sYB-tyumen
        Junior Member
        • May 2010
        • 4

        #4
        I think, yes.
        It is confusing when I see that zabbix has been tested on Ubuntu and there are no upstart jobs in installation packet.

        But there are 2 things to pay attention for:
        1) /var/run/zabbix is not a default path for pid files
        2)
        Code:
                  and started mysql)
        does NOT guarantee that zabbix server process will be able to connect to mysql. It only means that zabbix server process starts after mysql process (if your database is large enough, myslq can be started, but not ready to accept connections). May be a little pause (or better some mysql connection test) will be suitable before “exec” statement.

        Comment

        • richlv
          Senior Member
          Zabbix Certified Trainer
          Zabbix Certified SpecialistZabbix Certified Professional
          • Oct 2005
          • 3112

          #5
          Originally posted by sYB-tyumen
          2)
          Code:
                    and started mysql)
          does NOT guarantee that zabbix server process will be able to connect to mysql. It only means that zabbix server process starts after mysql process (if your database is large enough, myslq can be started, but not ready to accept connections). May be a little pause (or better some mysql connection test) will be suitable before “exec” statement.
          how do other software packages handle that ?
          Zabbix 3.0 Network Monitoring book

          Comment

          • nelsonab
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Sep 2006
            • 1233

            #6
            You might also want to check the Fedora RPM for Zabbix. Fedora has also moved to upstart. It might also be a good reference point.
            RHCE, author of zbxapi
            Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
            Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

            Comment

            • richlv
              Senior Member
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Oct 2005
              • 3112

              #7
              Originally posted by nelsonab
              You might also want to check the Fedora RPM for Zabbix. Fedora has also moved to upstart. It might also be a good reference point.
              could you please post the examples here ? is there some common way to deal with database availability when starting up ?
              Zabbix 3.0 Network Monitoring book

              Comment

              • sYB-tyumen
                Junior Member
                • May 2010
                • 4

                #8
                One of the methods is listed in zabbix agent's configuration file.

                I tried this in a pre-start section of upstart job:
                Code:
                  ZabbixConfig=/etc/zabbix/zabbix_server.conf
                  DBuser=""
                  DBpassword=""
                
                  if [ -f $ZabbixConfig ]
                  then
                    DBuser=`cat $ZabbixConfig | grep '^DBUser='`
                    DBuser="${DBuser##*=}"
                    DBpassword=`cat $ZabbixConfig | grep '^DBPassword='`
                    DBpassword="${DBpassword##*=}"
                
                    if [ -n "$DBuser" ] && [ -n "$DBpassword" ]
                    then
                
                      i=0
                
                      while [ i -le 5 ]
                      do
                        Test=`mysqladmin -u$DBuser -p$DBpassword ping|grep alive|wc -l`
                
                        if [ $Test=1 ]
                        then
                          i=100
                        else
                          sleep 5
                          i=`expr $i + 1`
                        fi
                      done
                    fi
                  fi
                Tried "for" loop with "break" when $Test=1, but it looks like "break " statement breaks entire upstart job execution.

                Comment

                • richlv
                  Senior Member
                  Zabbix Certified Trainer
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Oct 2005
                  • 3112

                  #9
                  added the files from the first post to svn.
                  Zabbix 3.0 Network Monitoring book

                  Comment

                  • g.vecchi
                    Member
                    • Dec 2010
                    • 44

                    #10
                    Hi all!
                    I'm new of upstart and I have the same problem with MySQL and Zabbix on Ubuntu Server 10.04.2

                    Can you post the entire correct scripts and the shell command to configure them please?

                    Many thanks!

                    Comment

                    • g.vecchi
                      Member
                      • Dec 2010
                      • 44

                      #11
                      Ok, I've created working configurations files.

                      See attachments.
                      Attached Files

                      Comment

                      • elvar
                        Senior Member
                        • Feb 2008
                        • 226

                        #12
                        Originally posted by scanch
                        Hello,

                        Here are simple upstart scripts (tested under ubuntu 10.04.1 server) for zabbix-server and zabbix-agent.
                        Any feedback & suggestions are welcomed.

                        zabbix-agent.conf:
                        Code:
                        # zabbix-agent - Start zabbix agent
                        description     "Zabbix Agent"
                        author          "S. CANCHON"
                        start on runlevel [2345]
                        stop on runlevel [016]
                        respawn
                        expect daemon
                        exec /usr/sbin/zabbix_agentd
                        zabbix-server.conf:
                        Code:
                        # zabbix-server - Start zabbix server
                        description     "Zabbix Server"
                        author          "S. CANCHON"
                        start on (runlevel [2345]
                                  and started mysql)
                        stop on runlevel [016]
                        respawn
                        expect daemon
                        exec /usr/sbin/zabbix_server
                        Just have to copy them in /etc/init/ and control them with upstart tools.

                        I copied it to /etc/init.d and then did the following...


                        root@zabbix01:/etc/init.d# update-rc.d zabbix-server defaults
                        update-rc.d: warning: /etc/init.d/zabbix-server missing LSB information
                        update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
                        Adding system startup for /etc/init.d/zabbix-server ...
                        /etc/rc0.d/K20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc1.d/K20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc6.d/K20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc2.d/S20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc3.d/S20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc4.d/S20zabbix-server -> ../init.d/zabbix-server
                        /etc/rc5.d/S20zabbix-server -> ../init.d/zabbix-server

                        Then when I do /etc/init.d/zabbix-server start I get the following...


                        root@zabbix01:/etc/init.d# /etc/init.d/zabbix-server start
                        /etc/init.d/zabbix-server: line 2: description: command not found
                        /etc/init.d/zabbix-server: line 3: author: command not found
                        /etc/init.d/zabbix-server: line 4: syntax error near unexpected token `('
                        /etc/init.d/zabbix-server: line 4: `start on (runlevel [2345]'

                        Any ideas?

                        Kind regards,

                        Comment

                        • g.vecchi
                          Member
                          • Dec 2010
                          • 44

                          #13
                          You have to copy them into /etc/init NOT /etc/init.d

                          Bye!

                          Comment

                          • elvar
                            Senior Member
                            • Feb 2008
                            • 226

                            #14
                            Originally posted by g.vecchi
                            You have to copy them into /etc/init NOT /etc/init.d

                            Bye!

                            Thanks for what should have been obvious

                            Comment

                            • g.vecchi
                              Member
                              • Dec 2010
                              • 44

                              #15
                              YAW

                              Bye

                              Comment

                              Working...