-
Type:
Patch request
-
Resolution: Unresolved
-
Priority:
Trivial
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
I'm basing myself on the file /lib/systemd/system/zabbix-server.service shipped via the Debian/Ubuntu repository https://repo.zabbix.com for the package zabbix-server-pgsql:
The current file for zabbix-server is:
[Unit] Description=Zabbix Server After=syslog.target After=network.target After=postgresql.service [Service] Environment="CONFFILE=/etc/zabbix/zabbix_server.conf" EnvironmentFile=-/etc/default/zabbix-server Type=forking Restart=on-failure PIDFile=/run/zabbix/zabbix_server.pid KillMode=control-group ExecStart=/usr/sbin/zabbix_server -c $CONFFILE ExecStop=/bin/sh -c '[ -n "$1" ] && kill -s TERM "$1"' -- "$MAINPID" RestartSec=10s TimeoutSec=infinity LimitNOFILE=65536:1048576 [Install] WantedBy=multi-user.target
This file seem to have several issues.
In [Unit]:
- After=syslog.target should be removed, especially on modern system using journald, this doesn't make sense
- After=network.target, this doesn't warranty network availability, use After=network-online.target instead
- After=postgresql.service, this looks like a good idea, but it's not: if the database is on a separate host, this doesn't make sense
In [Service]:
- KillMode=control-group is the default, it should be removed.
- ExecStop=/bin/sh -c '[ -n "$1" ] && kill -s TERM "$1"' – "$MAINPID", in my tests, this creates infinite loops when trying to stop the server, it should simply be removed
- missing User=zabbix and Group=zabbix, I have tested the server with those parameters and it works perfectly
Things that should be modified but that require default settings modifications:
- RuntimeDirectory=zabbix_server: this would replace the old logic in /usr/lib/tmpfiles.d/zabbix-server.conf, which is deprecated, but it MUST use a different folder than the other zabbix daemon (especially the agent)
- PIDFile=/run/zabbix_server/zabbix_server.pid must be modified to match the previous change
This change require the following change in zabbix_server.conf:
PidFile=/run/zabbix_server/zabbix_server.pid
Also while at it, having the SocketDir value at /tmp is strange, either set PrivateTmp=true or just chnage the value to SocketDir=/run/zabbix_server.
Further optimisation should include the creation of a dedicated user for zabbix server (and proxy) that is different from the current zabbix user which should be reserved for the agent. But this is outside of the scope of this ticket.
I did look for the repository for the packaging of zabbix but didn't find it to create a PR.
In short, quick modification that doesn't require any modification of Zabbix:
[Unit] Description=Zabbix Server After=network-online.target [Service] Environment="CONFFILE=/etc/zabbix/zabbix_server.conf" EnvironmentFile=-/etc/default/zabbix-server Type=forking User=zabbix Group=zabbix PIDFile=/run/zabbix/zabbix_server.pid ExecStart=/usr/sbin/zabbix_server -c $CONFFILE LimitNOFILE=65536:1048576 Restart=on-failure RestartSec=10s TimeoutSec=infinity [Install] WantedBy=multi-user.target
Version with the new runtime directory, that require default values for PidFile to be modified:
[Unit] Description=Zabbix Server After=network-online.target [Service] Environment="CONFFILE=/etc/zabbix/zabbix_server.conf" EnvironmentFile=-/etc/default/zabbix-server Type=forking User=zabbix Group=zabbix RuntimeDirectory=zabbix_server PIDFile=/run/zabbix_server/zabbix_server.pid ExecStart=/usr/sbin/zabbix_server -c $CONFFILE LimitNOFILE=65536:1048576 Restart=on-failure RestartSec=10s TimeoutSec=infinity [Install] WantedBy=multi-user.target