Ad Widget

Collapse

Better init.d script, more flexible

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kai-Kai
    Senior Member
    • Apr 2009
    • 142

    #1

    Better init.d script, more flexible

    Hello,

    as I think Zabbix is really a wonderfull soft, I want to contribute to its developpment.
    I have compiled my own zabbix from sources and installed it in a custom directory. Then I would like to use init.d scripts which are given with sources... but for a custom installation, it doesn't work...

    So I've modified the script :

    Replacing :
    Code:
    NAME=zabbix_agentd
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/zabbix/bin
    DAEMON=/home/zabbix/bin/${NAME}
    DESC="Zabbix agent daemon"
    PID=/var/tmp/$NAME.pid
    By :
    Code:
    NAME=zabbix_agentd
    CONFIGFILE=zabbix_agentd.conf
    ZABPATH=/usr/local/zabbix
    
    CONFPATH="${ZABPATH}/etc/${CONFIGFILE}"
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:${ZABPATH}/sbin
    
    DAEMON="${ZABPATH}/sbin/${NAME}"
    OPTIONS="-c ${CONFPATH}"
    DESC="Zabbix agent daemon"
    PID="${ZABPATH}/var/tmp/${NAME}.pid"
    And replacing :
    Code:
      start)
            echo "Starting $DESC: $NAME"
            start-stop-daemon --oknodo --start --pidfile $PID \
                    --exec $DAEMON
            ;;
    By :
    Code:
      start)
            echo "Starting $DESC: $NAME"
            start-stop-daemon --oknodo --start --pidfile $PID \
                    --exec ${DAEMON} -- ${OPTIONS}
            ;;
    In this way, the daemon use my own config file, with my user, in my path...

    But as it's my first init script, I would like to have feedbacks about this. And if you think this idea is good, I think it could be modified in the next release of zabbix.

    What do you think about it ?
    Last edited by Kai-Kai; 03-07-2009, 14:54.
  • Kai-Kai
    Senior Member
    • Apr 2009
    • 142

    #2
    On my machin, the "restart" command doesn't works properly... I think the start is a bit too quick...
    I've also replaced :
    Code:
            $0 stop
            $0 start
    with :
    Code:
            $0 stop
            sleep 2
            $0 start
    And now it works fine.
    Last edited by Kai-Kai; 23-06-2009, 17:03. Reason: more precisions

    Comment

    • Calimero
      Senior Member
      • Nov 2006
      • 481

      #3
      To make it even more "Debianish" you could set reasonable default values (paths) in the script itself and try and source /etc/default/zabbix - if present - which would override variables when necessary.

      Comment

      • Kai-Kai
        Senior Member
        • Apr 2009
        • 142

        #4
        Yes, values I've choosen in the example script are my real values.
        I've put all what is relative to zabbix in /usr/local/zabbix instead of using /etc, /bin etc...

        Why ? I think because I've discovered Zabbix on Solaris, and Solaris runs this way (and I prefere this way to do, because I think it's more cleared to group all the files of an application).

        But the default script, given with the sources should naturally use default values, more "debianish" in the variables. And the user customize then the values...

        Is it what you mean ?

        Comment

        • Calimero
          Senior Member
          • Nov 2006
          • 481

          #5
          I mean that the Debian way of overriding startup variables is to source a file named /etc/default/<app_name>

          But on the other hand we're talking about custom manual installs (and not .deb packages) so it's no big deal: if you install manually you can spend an extra 5 seconds to set the right path in your startup script.

          On the other hand, if you create .deb packages for redistribution, the /etc/default/zabbix approach seems a bit better.

          Comment

          • Kai-Kai
            Senior Member
            • Apr 2009
            • 142

            #6
            Yes, I agree with you.
            But I think that as sources are here to allow people making custom install instead of using deb package for example, it could be interesting if the scripts given in the sources were ready to be customized.

            As I haven't use start-stop-daemon before, I had to make some searches before managing to do what I want (because -c is also an option of start-stop-daemon and was interpreted so at the beginning). That's why I made this suggestion, to help other people wanting to do a custom install in the future...

            But pehaps this is just a useless idea interesting only me... ^^ if it's effectively that, my script is okay for me...

            Comment

            • Kai-Kai
              Senior Member
              • Apr 2009
              • 142

              #7
              I come back on this topic because there's something I don't understand.
              If you try to launch zabbix as root user, with :
              /path/zabbix_agentd -c /path2/zabbix_agentd.conf
              it fails. You have to be logged as zabbix user.

              But when you use the init.d script, the daemon starts, with the user zabbix, whereas it's not specified in the script, and not in the config file...

              Where does it find the right user ?...

              I have added --chuid ${USER} on the start line, --user ${USER} on the stop line of start-stop-daemon and USER='zabbix' at the beginning of the script... but before I've added that, it seems to work and in the script given with in the sources, the user is not specified...

              Can anybody explain it to me ?
              Last edited by Kai-Kai; 03-07-2009, 15:09.

              Comment

              • Calimero
                Senior Member
                • Nov 2006
                • 481

                #8
                if you start zabbix (agent or server) as root, it will drop privileges by switching to 'zabbix' (this is hardcoded in src/libs/zbxnix/daemon.c).

                if you start zabbix as non-root (any user with uid/gid != 0), it won't complain and won't try to switch user.

                Comment

                • Kai-Kai
                  Senior Member
                  • Apr 2009
                  • 142

                  #9
                  Ok, it's hardcoded in the soft.
                  That answers my question.

                  So the chuid I've added in my script allows people to use another username than zabbix if neeeded. Useless as far as I'm concerned, but can be usefull to anybody else I think.

                  Thanks.

                  Comment

                  Working...