📜 ⬆️ ⬇️

Debian-packages with a human face on the example of Zabbix 1.8

Two things forced me to write this article: first, there is a feeling that after articles like " we are doing a debian-package on the knee, " most people in Habravchan will be convinced that perverts have come up with debian-packages. Secondly, zabbix 1.8 was released - a great monitoring system, in which, judging by the news, at last they were tackling usability problems in the admin interface.

The link between these two events is that zabbix 1.8 is not yet available in the repositories of ubunt, and compiling and installing something from the sources on the production servers is, of course, an unworthy gentleman job. In general, there is a reason to show how debian packages are made.

So hehe, let's get started :)
')
apt-get install dh-make devscripts cdbs libmysqlclient-dev libcurl4-gnutls-dev
wget sunet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8/zabbix-1.8.tar.gz
tar zxvf zabbix-1.8.tar.gz
cd zabbix-1.8
dh_make --createorig


The question dh_make, what type of package we want to create, you need to answer "b" (cdbs). As a result, a template package will be created, with a bunch of files in the debian directory for all occasions (we will remove most of it later).

Creating packages is still a little bit of shamanism and magic. The fact is that programs that are simpler than zabbix can be terminated at this stage. Those. if to install the program you only need to do ./configure && make install, then everything is ready, you can build and install. Zabbix is ​​a somewhat more complicated option, so there are still several steps ahead:



Let's start by opening the debian / control file and specifying ourselves as the creator of the package, and at the same time we will list the packages that should come to the server along with the installation of zabbix. To do this, find the line 'Depends' and add the following to its end: "fping, adduser, apache2, php5, php5-mysql, php5-gd".

Typically, the configure script can be called without parameters and it will generate a viable config, but for zabbix this is not the case - it needs separate options to enable the compilation of the server part and the agent. In our case, this is configured in the debian / rules file, we will add the following to its end:
DEB_CONFIGURE_USER_FLAGS := --enable-server --with-mysql --with-libcurl


Binary files will go into the / usr / bin and / usr / sbin directories by themselves, and the php interface and config files must be set manually. The easiest and most visual way to do this is to create a debian / install file, and describe everything in it like this:
frontends/php/* usr/share/zabbix/
misc/conf/zabbix_server.conf etc/zabbix


In addition, for normal operation, Zabbix also needs directories for storing log files and locks. Creating them is also easy - just list them in the debian / dirs file:
/var/log/zabbix-server
/var/run/zabbix-server


Now it's an init script. In the zabbix sources, the init script is (misc / init.d / debian / zabbix-server), but without file processing it will not work. Therefore, it is better to replace it with a script from ubunt ( from here ), which must be saved under the name debian / init (on the final system, it will be called /etc/init.d/zabbix - magic).

To configure logrotate, you just need to put the config in the right place:
cat > debian/logrotate
/var/log/zabbix-server/zabbix_server.log {
daily
rotate 7
compress
missingok
notifempty
create 0640 zabbix zabbix
sharedscripts
}
^D


It is very convenient when a package with a web interface sets itself a config for an apache:
mkdir misc/apache2-vhosts
cat > misc/apache2-vhosts/zabbix
<VirtualHost *>
ServerName zabbix.example.com
ServerAdmin admin@example.com

DocumentRoot /usr/share/zabbix

CustomLog /var/log/apache2/zabbix_access.log combined
ErrorLog /var/log/apache2/zabbix_error_log
</VirtualHost>
^D
echo "misc/apache2-vhosts/zabbix etc/apache2/sites-available" >> debian/install


Not all. Someone must create a user zabbix, set up an init script to autoload and fix permissions. The easiest way to do this is in a postinstall script, for this you need to take its template:
mv debian/postinst.ex debian/postinst
vim debian/postinst


And after the line 'configure)', but before the ';;' write the following:
#
useradd zabbix || echo "User zabbix was not added"

#
chown zabbix:zabbix /var/log/zabbix-server /var/run/zabbix-server

# - -:
chown www-data /usr/share/zabbix/conf
chmod 775 /usr/share/zabbix/conf

# :
update-rc.d zabbix-server defaults

# :
a2ensite zabbix
invoke-rc.d apache2 reload


One detail remained: with the standard PHP settings, the zabbiks interface will not start, you need to edit max_execution_time and a few more parameters. If we were preparing a package for a home server-torrent, then, of course, it would be easier to fix php.ini directly. But ideologically it is more correct to put these settings in the package. You can do it like this:

mkdir misc/php.conf
cat > misc/php.conf/zabbix.ini
post_max_size = 16M
max_execution_time = 300
mbstring.func_overload = 2
^D

echo "misc/php.conf/zabbix.ini etc/php5/conf.d" >> debian/install


Now we need to fix the default configs so that the paths to the logs and pid files we need are indicated there.

And, in general, everything. You can build a package with the debuild command, install it with dpkg -i <package.deb> and apt-get install -f.

Hopefully, I managed to demonstrate that debian, among other things, is a convenient and thoughtful environment for porting applications; Creating a new package is quite an alternative to installing programs that are not in the repository, even if we are talking about one installation.

If the topic is interesting, I can continue. This time, a lot of things are left behind the scenes - what dehelper scripts are, and CDBS, how to debug package dependencies, and why pbuilder is one of my favorite tools.

PS If you have your own open-source project, then I can help with its packaging, please contact.

PPS: Transfer this post to some thematic blog, please. Thanks for the karma! Moved myself :)

UPD:: Several updated version of the article in my blog: alexey.sveshnikov.ru/blog/2010/03/29/zabbix-debianization .

Source: https://habr.com/ru/post/78086/


All Articles