I have been looking at the Systems V Initialisation scripts for the zabbix agent. I have started from the debian code and am testing using Ubuntu 9.
The code is not LSB compliant in a couple of ways and this means that installing the links using update-rc.d is more difficult than it otherwise might be. It may also fail to work with the red-hat based chkconfig which I have seen require certain comment lines. These are resolved by installing the mandatory comment block. See http://wiki.debian.org/LSBInitScripts. The code makes no use of the the /lib/lsb/init-functions; start-stop-daemon is part of dpkg utilities and is file system addressable binary. I plan to amend the script to include the comment block and use the log_msg functions.
The environment variables need to be made installation specific. The debian code assumes that there is a /home/zabbix/bin directory, which since the default location is /usr/local seems a bit odd, but the fact is that these variables need to be checked and fixed. Also the script appends ~/bin to the PATH and not ~/sbin. This is not right. Most importantly the PATH variable needs to be amended to include the location of the binary. The path would be best fixed in the ./configure script, but I don't plan to do this.
I have implemented a status method which relies on zabbix_get.
Is this sensible? Does --enable-agent ensure the build of zabbix_get?
The help function assumes that the scriptname is the same as the program name. So I have coded a SCRIPTNAME variable. (I should probably have used $0.) The script name is only consumed in the help method. It is referred to using $0 in the restart method.
Ubuntu keeps its .pid files in /var/run which is a root:root directory. This means that the zabbix_agentd cannot write the PID there with the default configuration. I can think of a couple of ways round this.
I can change the permissions on /var/run to permit the zabbix user to write into it. I could use /var/tmp which is 777. I could create a /var[/run]/zabbix directory and chown it to zabbix. For the short term, I think I'll use /var/tmp. I assume that any attempt to use start-stop-daemon's --user or --group parameters will be overwritten by the zabbix binary. (If I test this, I'll update this thread.)
Additionally, the /etc/zabbiz/zabbix_agentd.conf defines where the zabbix agent writes the PID file and so we have the ablity to muck up here, with the script passing an erroneous pid file address to the start-stop-daemon program. I have replaced the code with the following
This fixes an error configuration I discovered. Both the zabbix_agentd and the start-stop-daemon now use the same PID file. This involves invoking external programs, but we only run this occasionally and they're both in bin.
I have placed a sleep 3 between the start and stop calls in the restart|force-reload method. It seems to prefer this. I would have prefered to code the methods as functions and invoked the functions from the method case selection statement but I have left it as it is for the moment. Reusing the code, which this does is the better thing to do IMO.
I have attatched the whole file if you want to read it. If the Zabbix committers like what I have done, perhaps they'll include it in the distribution. Anyone please comment to improve this code.
For Ubuntu I am going to use the LSB functions to use the log* functions to control the console display.
I shall next look at the Fedora server script.
The code is not LSB compliant in a couple of ways and this means that installing the links using update-rc.d is more difficult than it otherwise might be. It may also fail to work with the red-hat based chkconfig which I have seen require certain comment lines. These are resolved by installing the mandatory comment block. See http://wiki.debian.org/LSBInitScripts. The code makes no use of the the /lib/lsb/init-functions; start-stop-daemon is part of dpkg utilities and is file system addressable binary. I plan to amend the script to include the comment block and use the log_msg functions.
The environment variables need to be made installation specific. The debian code assumes that there is a /home/zabbix/bin directory, which since the default location is /usr/local seems a bit odd, but the fact is that these variables need to be checked and fixed. Also the script appends ~/bin to the PATH and not ~/sbin. This is not right. Most importantly the PATH variable needs to be amended to include the location of the binary. The path would be best fixed in the ./configure script, but I don't plan to do this.
I have implemented a status method which relies on zabbix_get.
Code:
case $( zabbix_get -s127.0.0.1 -k agent.ping 2> /dev/null ) in 1) exit 0 ;; *) exit 1 ;; esac
The help function assumes that the scriptname is the same as the program name. So I have coded a SCRIPTNAME variable. (I should probably have used $0.) The script name is only consumed in the help method. It is referred to using $0 in the restart method.
Ubuntu keeps its .pid files in /var/run which is a root:root directory. This means that the zabbix_agentd cannot write the PID there with the default configuration. I can think of a couple of ways round this.
I can change the permissions on /var/run to permit the zabbix user to write into it. I could use /var/tmp which is 777. I could create a /var[/run]/zabbix directory and chown it to zabbix. For the short term, I think I'll use /var/tmp. I assume that any attempt to use start-stop-daemon's --user or --group parameters will be overwritten by the zabbix binary. (If I test this, I'll update this thread.)
Additionally, the /etc/zabbiz/zabbix_agentd.conf defines where the zabbix agent writes the PID file and so we have the ablity to muck up here, with the script passing an erroneous pid file address to the start-stop-daemon program. I have replaced the code with the following
Code:
CONFIG_FILE=/etc/zabbix/${NAME}.conf
PID=$( cat $CONFIG_FILE | egrep ^PidFile= | cut -f2 -d"=" )
I have placed a sleep 3 between the start and stop calls in the restart|force-reload method. It seems to prefer this. I would have prefered to code the methods as functions and invoked the functions from the method case selection statement but I have left it as it is for the moment. Reusing the code, which this does is the better thing to do IMO.
I have attatched the whole file if you want to read it. If the Zabbix committers like what I have done, perhaps they'll include it in the distribution. Anyone please comment to improve this code.
For Ubuntu I am going to use the LSB functions to use the log* functions to control the console display.
I shall next look at the Fedora server script.
- ListenIP directive...
Comment