Packaging zabbix-agent 1.8.1 for Solaris 10
(post moved from old blog)
I had no idea how to make Solaris packages but after trying to squeeze the zabbix agent into boxes via ops center I realised it was time to learn.
Thanks to a couple of websites for info:
How to make a Solaris package (pkg format) and
Adding Service Management Facility (SMF) to Packages
I wouldn't necessarily say this is the correct method or the best method… but it works (ymmv 8-)
The package sets up the zabbix user and a zabbix-agent smf service which is disabled by default. We need to copy /etc/zabbix/zabbix_agentd.conf.sample to zabbix_agentd.conf and edit the hostname and server fields before you can enable the service. The user and service are removed when the package is uninstalled.
One caveat - the package assumes that no zabbix user exists !
So here's how…
Create the following files:
- Makefile - easy pkg generation
PKG=ASMzaba #possible ARCH values are i386, sparc, all ARCH=i386 PKGFILE=$(PKG)-$(ARCH).pkg pkg: pkgmk -o -d /tmp -a $(ARCH) touch $(PKGFILE) pkgtrans -s /tmp $(PKGFILE) $(PKG) rm -r /tmp/$(PKG) @echo check current directory for .pkg files
- pkginfo - package definition info
BASEDIR=/ TZ=Australia/Melbourne PKG=ASMzaba NAME=zabbix-agent ARCH=i386 VERSION=1.8.1 CATEGORY=system DESC=zabbix agent install package VENDOR=ASM EMAIL=some@email.address PKGSAV=/var/sadm/pkg/ASMzaba/save
- prototype - file selection - path on left of = is where it should go, right is where it is now
i pkginfo i preinstall i postinstall i preremove i postremove d none etc/zabbix 0750 zabbix sys f none etc/zabbix/README=README 0444 zabbix sys f none etc/zabbix/zabbix_agentd.conf.sample=etc/zabbix/zabbix_agentd.conf.sample 0444 zabbix sys d none usr/local 0755 root root d none usr/local/bin 0755 root root f none usr/local/bin/zabbix_get=usr/local/bin/zabbix_get 0555 root bin f none usr/local/bin/zabbix_sender=usr/local/bin/zabbix_sender 0555 root bin d none usr/local/share 0755 root root d none usr/local/share/man 0755 root root d none usr/local/share/man/man1 0755 root root f none usr/local/share/man/man1/zabbix_get.1=usr/local/share/man/man1/zabbix_get.1 0644 root bin f none usr/local/share/man/man1/zabbix_sender.1=usr/local/share/man/man1/zabbix_sender.1 0644 root bin d none usr/local/share/man/man8 0755 root root f none usr/local/share/man/man8/zabbix_agentd.8=usr/local/share/man/man8/zabbix_agentd.8 0644 root bin d none usr/local/sbin 0755 root root f none usr/local/sbin/zabbix_agent=usr/local/sbin/zabbix_agent 0555 root bin f none usr/local/sbin/zabbix_agentd=usr/local/sbin/zabbix_agentd 0555 root bin f none var/svc/manifest/site/zabbix-agent.xml=zabbix-agent.xml 0644 root bin
Note you can generate this with the pkgproto command although it seems you will need awk afterwards ;-)
- preinstall
# zabbix-agent preinstall useradd -c "Zabbix Agent" -d /etc/zabbix -s /usr/bin/false zabbix
- postinstall
# zabbix-agent postinstall /usr/sbin/svccfg import /var/svc/manifest/site/zabbix-agent.xml &>/dev/null 2>&1 cat /etc/zabbix/README exit 0
- preremove
# zabbix-agent - preremove /usr/sbin/svcadm disable -s zabbix-agent &>/dev/null 2>&1 /usr/sbin/svccfg delete zabbix-agent >/dev/null 2>&1 exit 0
- postremove
# zabbix-agent postremove userdel zabbix
- zabbix-agent.xml - smf service definition
<?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM"/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <service_bundle type="manifest" name="zabbix-agent"> <service name="application/zabbix-agent" type="service" version="5"> <create_default_instance enabled="false"/> <single_instance/> <dependency name="fs-local" grouping="require_all" restart_on="none" type="service"> <service_fmri value="svc:/system/filesystem/local"/> </dependency> <exec_method type="method" name="start" exec="/usr/local/sbin/zabbix_agentd" timeout_seconds="60"/> <exec_method type="method" name="stop" exec="/usr/bin/pkill zabbix_agentd" timeout_seconds="60"/> <stability value="Unstable"/> <template> <common_name> <loctext xml:lang="C">Zabbix Agent</loctext> </common_name> </template> </service> </service_bundle>
- README - displayed at pkg install time
you will need to copy /etc/zabbix/zabbix_agentd.conf.sample to /etc/zabbix/zabbix_agentd.conf and edit the Server and Hostname fields before you can enable the smf service with 'svcadm enable zabbix-agent'
Once these are all created you need to create the software subdirs - these should be:
etc/ etc/zabbix etc/zabbix/zabbix_agentd.conf.sample usr/ usr/local usr/local/bin usr/local/bin/zabbix_get usr/local/bin/zabbix_sender usr/local/share usr/local/share/man usr/local/share/man/man1 usr/local/share/man/man1/zabbix_get.1 usr/local/share/man/man1/zabbix_sender.1 usr/local/share/man/man8 usr/local/share/man/man8/zabbix_agentd.8 usr/local/sbin usr/local/sbin/zabbix_agent usr/local/sbin/zabbix_agentd
Now you can generate the package with 'make pkg'.
If you want to provision this with ops-center then just create the /etc/zabbix zabbix_agentd.conf from an example one from source or the zabbix website replacing server with your server's ip address and hostname with "^AM^server_hostname^AM^". This can then be updated by a server_hostname macro script that just returns the hostname:
#!/bin/sh hostname
You can then use ops-center to provision the package and config all in one go - start the smf in a postinstall script you use at setup time or create one just for the job.
There's a lot more to packaging than I have covered here or know (this was a learning exercise) but this at least gives me a nice clean way to install though ops-center.
EDIT: Probably would have helped if I had found the sun guide for application packaging first 8-)