Ad Widget

Collapse

Debian init.d script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghislain
    Senior Member
    • Jun 2005
    • 160

    #1

    Debian init.d script

    Hello,

    I don't know for you but i have troubles using the init.d scripts. I used the suckerd one and modified it as there is no server one ( i imagine this is the old name for the server) , it start but i cannot "restart" or "stop" it. This does not work.

    Do any user here have a debian set of init.d that works well for the server ? It seems that the pid written is not the pid of any processes, i suspect that zabbix fork itself in the background then drop the first process perhaps because of privileges issue (to run as zabbix user when launched by root ? ). This seem to be why the script cannot stop zabbix from running.

    It seems also that the pid file is created as 666, if i do not make error this can lead to security issues if root restart zabbix and some unpriviledged user put the pid of another process in this file ?

    Best regards,
    Ghislain.

    here is mine:

    #! /bin/sh
    #
    # Zabbix daemon start/stop script.
    #
    # Written by Alexei Vladishev <[email protected]>.

    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/zabbix/bin
    DAEMON=/opt/zabbix/bin/zabbix_server
    NAME=zabbix_server
    DESC="Zabbix daemon"

    test -f $DAEMON || exit 0

    set -e

    case "$1" in
    start)
    echo "Starting $DESC: $NAME"
    start-stop-daemon --oknodo --start --pidfile /tmp/$NAME.pid \
    --exec $DAEMON
    ;;
    stop)
    echo "Stopping $DESC: $NAME"
    start-stop-daemon --oknodo --stop --pidfile /tmp/$NAME.pid \
    --exec $DAEMON
    ;;
    restart|force-reload)
    #
    # If the "reload" option is implemented, move the "force-reload"
    # option to the "reload" entry above. If not, "force-reload" is
    # just the same as "restart".
    #
    # echo -n "Restarting $DESC: zabbix_server"
    $0 stop
    $0 start
    # start-stop-daemon --stop --quiet --pidfile \
    # /tmp/$NAME.pid --user zabbix --exec $DAEMON
    # sleep 1
    # start-stop-daemon --start --quiet --pidfile \
    # /tmp/$NAME.pid --user zabbix --exec $DAEMON
    # echo "$NAME."
    ;;
    *)
    N=/etc/init.d/$NAME
    # echo "Usage: $N {start|stop|restart|force-reload}" >&2
    echo "Usage: $N {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
    esac

    exit 0
    Regards,
    Ghislain.
  • Wolfgang
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified Specialist
    • Apr 2005
    • 116

    #2
    You are right.

    For debian you need to modify the location of the pid files within the the zabbix configuration files.

    See http://www.zabbix.com/forum/showthre...highlight=init
    http://www.intellitrend.de
    Specialised in monitoring large environments and Zabbix API programming.

    Comment

    • nikoula
      Junior Member
      • Jul 2005
      • 29

      #3
      patch

      Alexei,

      i don't know if you've planned to correct this init.d script, because in alpha12 it's not.
      to help you and others i give you the file which works with the correct zabbix default settings.

      See the attached file. (some comments may be in french )

      Nicolas.
      Attached Files

      Comment

      • ghislain
        Senior Member
        • Jun 2005
        • 160

        #4
        thank you both for the replies , change made hopefully it will work now.
        Regards,
        Ghislain.

        Comment

        • bbrendon
          Senior Member
          • Sep 2005
          • 870

          #5
          fyi, there are current debian packages here.

          deb http://mirror.opf.slu.cz/zabbix unstable contrib
          Unofficial Zabbix Expert
          Blog, Corporate Site

          Comment

          • elkor
            Senior Member
            • Jul 2005
            • 299

            #6
            I took my solaris init script and merged it with the debian one to make it a little more resilient.

            this script parses the PID file location as well as the server and client ports out of the configuration file so it doesn't need to be edited for special cases.. simply editing the config file is enough. On startup we also check for the presence of an existing PID file and check to see if zabbix is in memory with that PID, if it is we bail but if it's not we delete the file and start up, that will allow you to put it in non-standard locations and still not worry about it on reboot.

            finally, there is also a loop on restart to wait for sockets in TIME WAIT state to close so that you can kick it right back off and walk away instead of waiting 30 seconds.

            comments welcome, I also gave the default redhat one the same treatment, and I have a solaris copy as well, pretty basic stuff really but I like to idiot proof these things as much as possible.

            Code:
            #!/bin/bash
            # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
            #
            # Author:       Chris Regenye
            # Date:         08/19/2005
            # Info:         Debian startup script for zabbix agentd processes. Standard stuff.
            #
            # Modified:     Chris Regenye
            # Date:         09/20/2005
            # Info:         We now parse the zabbix ports out of the configuration file.
            #               Added a check to see if pending sockets are still open on restart.
            #               Check for PID file on startup, take action based on validity.
            #
            # Modified:     Chris Regenye
            # Date:         09/26/2005
            # Info:         Bug fix, script cleanup
            #
            # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
            PATH=/bin:/usr/bin:/sbin:/usr/sbin:/zabbix/bin
            DAEMON=/zabbix/bin/zabbix_agentd
            DESC="Zabbix agent"
            CONFFILE=/etc/zabbix/zabbix_agentd.conf
            
            # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
            pidfile=$( [ -f "$CONFFILE" ] && grep "PidFile=/" $CONFFILE | awk -F= '{print $2}' )
            zabport=$( [ -f "$CONFFILE" ] && grep "ListenPort=" $CONFFILE | awk -F= '{print $2}' )
            zabservport=$( [ -f "$CONFFILE" ] && grep "ServerPort=" $CONFFILE | awk -F= '{print $2}' )
            name=${DAEMON##*/}
            test -f $DAEMON || exit 0
            set -e
            case "$1" in
              start)
                    echo "Starting $DESC: $name"
                    [ ! "$pidfile" ] && echo "could not locate or encountered an error parsing configuration file $CONFFILE, exiting" && exit 1
                    if [ -f $pidfile ]
                    then
                            if [ "$(ps -ef | grep $(cat $pidfile) | grep $name)" ]
                            then
                                    echo "Zabbix agent appears to be running...  PID $(cat $pidfile)"
                                    exit 1
                            else
                                    rm $pidfile
                            fi
                    fi
                    while [ "$(netstat -an | grep $zabport)" ] || [ "$(netstat -an | grep $zabservport)" ]
                    do
                            echo "   Agent restart detected: waiting for old sockets to terminate"
                            sleep 5
                    done
                    start-stop-daemon --oknodo --start --pidfile $pidfile \
                            --exec $DAEMON &&  echo "$DESC Started" && exit 0
                    echo "$DESC Startup Failed"
                    ;;
              stop)
                    echo "Stopping $DESC: $name"
                    start-stop-daemon --oknodo --stop  --pidfile $pidfile \
                            --exec $DAEMON;
                    ;;
              restart|force-reload)
                    echo -n "Restarting $DESC"
                    $0 stop
                    $0 start
                    ;;
              *)
                    echo "Usage: $0 {start|stop|restart|force-reload}" >&2
                    exit 1
                    ;;
            esac
            exit 0
            edited for minor bugfix and script cleanup. this is idenentical to the file posted below.
            Last edited by elkor; 27-09-2005, 16:11.

            Comment

            • Alexei
              Founder, CEO
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2004
              • 5654

              #7
              May I ask you to attach this script. What version of Debian it supports?
              Alexei Vladishev
              Creator of Zabbix, Product manager
              New York | Tokyo | Riga
              My Twitter

              Comment

              • elkor
                Senior Member
                • Jul 2005
                • 299

                #8
                here you go. this is tested on our potato and woody machines, but I don't think there is anything in it that is particuarly version-dependent; it should run on all versions.

                this version is cleaned up with a minor bugfix, I'm going to edit the post above to reflect the contents of this file.

                added a ".txt" extension to the filename to allow for forum upload.

                edit: one more item of note; as the script parses the config file it does expect ListenPort, ServerPort, and PidFile to be defined there on their own line and with no comments that match. i.e.

                ListenPort=10050
                ServerPort=10051
                PidFile=/var/tmp/zabbix.pid


                comments or the default commented out entries may screw things up, so don't have entries like

                #ListenPort default 10050
                #ServerPort=10051

                or
                PidFile=/var/tmp/zabbix.pid #this is the default entry

                in your file. I could (and probably should) sanity check this but I don't want to modify the thing 100times in the same day, and in my envirionment I distribute the config file without comments so I didn't think to check until I uploaded it
                Attached Files
                Last edited by elkor; 27-09-2005, 16:23.

                Comment

                • ghislain
                  Senior Member
                  • Jun 2005
                  • 160

                  #9
                  ok, this work great for the agentd !



                  Now i still i have problems on the server start/stop


                  if i leave the script with

                  start-stop-daemon --oknodo --start --pidfile $pidfile \
                  --exec $DAEMON && echo "$DESC Started" && exit 0

                  and DAEMON=zabbix_server i got this:

                  ik61050:/etc/init.d# ./zabbixserver stop..
                  Stopping Zabbix server: zabbix_serverrep --help ยป.
                  start-stop-daemon: stat zabbix_server: No such file or directory


                  but if i put DAEMON=/usr/local/bin/zabbix_server i got :
                  ik61050:/etc/init.d# ./zabbixserver stop
                  Stopping Zabbix server: zabbix_server
                  No /usr/local/bin/zabbix_server found running; none killed.

                  also in the pid the number is not a good one. For exemple i launch zabbix and i get:


                  ├─zabbix_server(19253)
                  ├─zabbix_server(19255)
                  ├─zabbix_server(19257)
                  ├─zabbix_server(19260)
                  ├─zabbix_server(19262)
                  ├─zabbix_server(19264)
                  ├─zabbix_server(19266)
                  ├─zabbix_server(19268)
                  ├─zabbix_server(19270)
                  ├─zabbix_server(19272)
                  └─zabbix_server(19274)
                  ik61050:/etc/init.d# more /opt/zabbix/zabbix_server.pid
                  19251

                  as you see the pid is not the pid of the server or any of his processes....


                  so, what can i do ?
                  Last edited by ghislain; 29-11-2005, 13:15.
                  Regards,
                  Ghislain.

                  Comment

                  • elkor
                    Senior Member
                    • Jul 2005
                    • 299

                    #10
                    I use the exact same script for my server process.

                    In addition to the daemon name you allso need to change the value of CONFFILE so that it points to the proper one for zabbix_server. That will ensure that the script knows the correct location for the pid file.

                    Comment

                    • root_master
                      Junior Member
                      • Dec 2005
                      • 18

                      #11
                      Hello,

                      i've some trouble with the init script if i use a lot of host in my network.

                      because the init script checks if the port 10050 in use, at zabbix agend restart

                      but the problem is that the hosts the connections to the server opens from port 10050.

                      the problem - the restart doesn't work

                      use this

                      [ "$(netstat -an | grep '^tcp' | awk '{print $4}' | grep $zabport)" ]

                      instead of

                      [ "$(netstat -an | grep $zabport)" ]

                      root_master

                      Comment

                      Working...