Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#737 closed enhancement (wontfix)

systemd service unit file ignores sysconfig environment variables

Reported by: www.google.com/accounts/o8/id?id=AItOawmHdCp7WsIBiTMOYJ1Ol8MTvSmM9ZT1orM Owned by:
Priority: trivial Milestone:
Component: nginx-package Version: 1.6.x
Keywords: systemd Cc:
uname -a: Linux HOSTNAME 3.10.0-123.13.2.el7.x86_64 #1 SMP Fri Dec 12 19:51:03 EST 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.6.2 built by gcc 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

Description

At the moment the packacked systemd unit file use a hard path to the nginx configuration file.
It is easy to fix this for CONFFILE and NGINX already delivered by the nginx rpm.
You just need to source the sysconfig file described here:
http://fedoraproject.org/wiki/Packaging%3aSystemd#EnvironmentFiles_and_support_for_.2Fetc.2Fsysconfig_files

I already checked 1.7.x: same fix needed

Change History (4)

comment:1 Changed 5 years ago by thresh

Contrary to initscripts, variables sourced with EnvironmentFile? are passed to the binary specified by ExecStart? - so NGINX="/usr/sbin/nginx" will be passed and nginx process will think it's an upgrade time and will try to inherit sockets - which will fail.

I think that the proper solution for the case when one wants to launch multiple nginx instances with different binaries / configurations would be to use separate unit files.

comment:2 Changed 5 years ago by www.google.com/accounts/o8/id?id=AItOawmHdCp7WsIBiTMOYJ1Ol8MTvSmM9ZT1orM

NGINX can't be used in the service unit file because ExecStart? requires an absolut path to the binary.
I had to change the type from forking to simple because systemd killed nginx after 90 seconds using the EnvironmentFile?, this one works great:
Type=simple
EnvironmentFile?=-/etc/sysconfig/nginx
#PIDFile=/run/nginx.pid
ExecStartPre?=/usr/sbin/nginx -t -c $CONFFILE
ExecStart?=/usr/sbin/nginx -c $CONFFILE

I wanted to use the /etc/sysconfig/nginx-file because this one should not be changed during a rpm update. It is really trivial to make these changes to the service file until then the already included /etc/sysconfig/nginx is not in use and obsolete.

I will use a separate unit file because the unit file could be overwritten during an update.

comment:3 Changed 5 years ago by thresh

  • Resolution set to wontfix
  • Status changed from new to closed

NGINX can't be used in the service unit file because ExecStart?? requires an absolut path to the binary.

Indeed, but default /etc/sysconfig/nginx sets it so it will be inherited by launched nginx proccess.

I had to change the type from forking to simple because systemd killed nginx after 90 seconds using the EnvironmentFile?

This happens exactly because this variable is inherited.

I will use a separate unit file because the unit file could be overwritten during an update.

This is indeed a proper solution.

comment:4 Changed 5 years ago by www.google.com/accounts/o8/id?id=AItOawmHdCp7WsIBiTMOYJ1Ol8MTvSmM9ZT1orM

Why not just remove NGINX from /etc/sysconfig/nginx instead of delivering an unused configuration file? Most sysconfig files don't contain a binary path. I think this would make a more redhat compatible rpm package(which should be a target since you publish rpms for rhel).

Note: See TracTickets for help on using tickets.