Ad Widget

Collapse

Rights of logs file zabbix_agentd.log

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SLMitch
    Member
    • May 2006
    • 39

    #1

    Rights of logs file zabbix_agentd.log

    I have seen a bug with the right of log for zabbix_agentd : Indeed, if the log file don't exist, he is created with root as owner, and zabbix can't write in it.

    This is a patch who move the first "touch" of the lof file after fork in user zabbix is done :



    Code:
    diff -ru zabbix-1.1-orig/src/zabbix_agent/zabbix_agentd.c zabbix-1.1/src/zabbix_agent/zabbix_agentd.c
    --- zabbix-1.1-orig/src/zabbix_agent/zabbix_agentd.c    2006-06-08 15:21:33.000000000 +0200
    +++ zabbix-1.1/src/zabbix_agent/zabbix_agentd.c 2006-06-08 15:26:37.000000000 +0200
    @@ -204,6 +204,12 @@
    
            }
    
    +       if(CONFIG_LOG_FILE == NULL)
    +               zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
    +       else
    +               zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);
    +
    +
            if( (pid = fork()) != 0 )
            {
                    exit( 0 );
    @@ -543,11 +549,6 @@
            init_metrics();
            init_config();
    
    -       if(CONFIG_LOG_FILE == NULL)
    -               zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
    -       else
    -               zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);
    -
            load_user_parameters();
    
            switch(task)
  • Alexei
    Founder, CEO
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2004
    • 5654

    #2
    Thanks for the patch. The problem is fixed.
    Alexei Vladishev
    Creator of Zabbix, Product manager
    New York | Tokyo | Riga
    My Twitter

    Comment

    • vrtareg
      Senior Member
      • May 2006
      • 293

      #3
      Hi

      The same problem is present in server code.

      Regards
      Areg

      Comment

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

        #4
        It has been fixed as well.
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • vrtareg
          Senior Member
          • May 2006
          • 293

          #5
          Hi

          Thank you.

          Another question. Is it possible to change PID file creation part?
          If it will be created as root it can be placed in /var/run and it will be possible to stop zabbix server and agent via killproc function (for init.d scripts).
          I try to change creation order in code but it seems that the first agentd or server process forks one and more child processes under zabbix user and exit.
          In this case in pid file i get nonexistent process number and killproc kills not correct process.

          You can find my attached scripts and small patch in this thread:


          Regards
          Areg

          Comment

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

            #6
            Originally posted by vrtareg
            Another question. Is it possible to change PID file creation part?
            If it will be created as root it can be placed in /var/run and it will be possible to stop zabbix server and agent via killproc function (for init.d scripts).
            Is it standard behavior of daemon processes?

            When a daemon starts as root:

            1. It creates PID file as root
            2. chown(zabbix)

            Right?
            Alexei Vladishev
            Creator of Zabbix, Product manager
            New York | Tokyo | Riga
            My Twitter

            Comment

            • vrtareg
              Senior Member
              • May 2006
              • 293

              #7
              Yes, you are right

              But in pid file writes the pid of the first process started from zabbix user, not the root process pid which will exit after starting child processes.
              Does i am right or no?
              If i start zabbix_agentd or zabbix_server process it do the following steps:

              1. check is it runnig from root?
              2. check if zabbix user present?
              3. fork n child processes from zabbix user
              4. exit

              In this case in pid file writes the main process pid number which dont exists anymore after running child processes.
              After this when init.d script try to stop daemon it check pid file, read pid from It and try to send TERM sygnal to this process.
              If process with this pid don.t exests it sends TERM sygnal to random process named zabbix_server or zabbix_agentd.
              After this server or agent dies abnormaly because they see that one of the threads dies.

              Regards
              Areg

              P.S. Sorry for my not good English. If i describe something not correct please tell me.

              Comment

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

                #8
                Thanks for the explanation, the PID issue will be fixed as well.
                Alexei Vladishev
                Creator of Zabbix, Product manager
                New York | Tokyo | Riga
                My Twitter

                Comment

                • just2blue4u
                  Senior Member
                  • Apr 2006
                  • 347

                  #9
                  i created the directory /var/run/zabbix/ with drwxr-xr-x for zabbix. so zabbix can put its pid-file there...
                  Big ZABBIX is watching you!
                  (... and my 48 hosts, 4513 items, 1280 triggers via zabbix v1.6 on CentOS 5.0)

                  Comment

                  • vrtareg
                    Senior Member
                    • May 2006
                    • 293

                    #10
                    Originally posted by just2blue4u
                    i created the directory /var/run/zabbix/ with drwxr-xr-x for zabbix. so zabbix can put its pid-file there...
                    This is not good solution because killproc function from /etc/rc.d/init.d/functions file look only in /var/run directory for the pid files.
                    If You call "killproc zabbix_server" it try to find /var/run/zabbix_server.pid file, read pid from it and send TERM sygnal to it.

                    This is correct way to stop program.

                    Regards
                    Areg

                    Comment

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

                      #11
                      Originally posted by vrtareg
                      Yes, you are right

                      But in pid file writes the pid of the first process started from zabbix user, not the root process pid which will exit after starting child processes.
                      Does i am right or no?
                      Yes, you're right. Honestly I do not see how this can be fixed... Indeed the root process exits and other processes have zabbix ownership.
                      Alexei Vladishev
                      Creator of Zabbix, Product manager
                      New York | Tokyo | Riga
                      My Twitter

                      Comment

                      • vrtareg
                        Senior Member
                        • May 2006
                        • 293

                        #12
                        Originally posted by Alexei
                        Yes, you're right. Honestly I do not see how this can be fixed... Indeed the root process exits and other processes have zabbix ownership.
                        I think that root process can work and wait for the external kill or term sygnal, and also checks child processes.
                        You can check that this process dont crate any connections and dont listen to any ports.
                        I think that in this case the pid file and log file problems can be solved.
                        Alsi you can put log files in standart /var/log directory and rotate them by logrotate.

                        Many programs in Linux rotates their log files by the -HUP command like this:

                        /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
                        sharedscripts
                        postrotate
                        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
                        endscript
                        }

                        This is a standatd logrotate script for syslog. You can find them in /etc/logrotate.d/syslog file in any Linux RedHat like distribution.

                        It will be betther to do this because you can send messages from the child processes to main process to write messages to log file.

                        For example apache web server work like this. It starts one process from the rot which will do absolutely nothing except managing log files, pid file and listening port 80. if someone try to connect to server, main process starts child process under some unprivileged user (apache) and child process starting to handle html, php and other files handling.

                        Regards
                        Areg

                        Comment

                        Working...