Opened 7 years ago

Closed 7 years ago

#1380 closed defect (fixed)

nginx does not clean up old sysvinit scripts with new version that provides systemd unit file

Reported by: Niels Hendriks Owned by: thresh
Priority: minor Milestone:
Component: nginx-core Version: 1.13.x
Keywords: init, sysvinit, systemd, boot Cc:
uname -a: Linux beheer 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2 (2017-04-30) x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.13.5
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1t 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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/ --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'



The new nginx version for Debian provides a systemd unit file. The old version had a file generated through the /etc/init.d/nginx file (/run/systemd/generator.late/nginx.service).

The new version is /lib/systemd/system/nginx.service

We use Ansible to deploy our installations. Because the old /etc/init.d/ scripts are not deleted and the /etc/rc*.d/S01nginx symlinks are still present Ansible assumes nginx is already configured to start at boot.

However, because now there is also an actual nginx systemd unit file, which is disabled by default this assumption is incorrect. Because of this, nginx is not automatically started after a server reboot.

Could nginx automatically remove these symlinks and the /etc/init.d/ script now that it has an actual systemd unit file? It seems that the old sysvinit files are now no longer needed.

Thank you!


Change History (5)

comment:1 by thresh, 7 years ago

Owner: set to thresh
Status: newassigned

We shouldnt remove /etc/init.d scripts on systemd-enabled debian/ubuntu, because those are still used for non-standard targets like upgrade.

I'm also not sure packages should touch rc.*d symlinks, however I need to dig some information on that.

comment:2 by Niels Hendriks, 7 years ago

Hi Thresh,

Thanks for your response.
I extracted the deb package I got with apt-get download nginx (nginx_1.13.5-1~jessie_amd64.deb) and perhaps this is a better solution:
In the postinst file the following code is present:

# Automatically added by dh_installinit
if [ -x "/etc/init.d/nginx" ]; then
        update-rc.d nginx defaults >/dev/null || exit $?
# End automatically added section

Perhaps it simply requires another block to check if it is a systemd system and in that case enable the unit file through systemd. In the postrm script there is already a code block to check for systemd, so copying that logic it would be something like this to add in the postinst block (untested)

if [ -d /run/systemd/system ] ; then
        systemctl enable nginx >/dev/null || exit $?

Perhaps it should even skip the update-rc.d nginx defaults block alltogether if it is a systemd system, since systemd will already automatically do this as well it seems:

# systemctl enable nginx
Synchronizing state for nginx.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d nginx defaults
insserv: warning: current start runlevel(s) (empty) of script `nginx' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `nginx' overrides LSB defaults (0 1 6).

comment:3 by thresh, 7 years ago

Perhaps it simply requires another block to check if it is a systemd system and in that case enable the unit file through systemd

Yeah, and it is supposed to be added by debhelper, which I assumed it will do when it sees a .service file. Of course, it's not that simple and .service files need to be explicitely mentioned in rules to be properly managed by post-scripts.

The following patch on seems to help, can you test it locally, too?

diff -r e2b3abb6eeb2 debian/
--- a/debian/	Tue Sep 12 00:21:29 2017 +0100
+++ b/debian/	Thu Sep 14 13:04:52 2017 +0000
@@ -107,11 +107,13 @@
 		-e 's/%%DEFAULTSTOP%%/0 1 6/g' \
 		< debian/ > debian/nginx.init
 	dh_installinit -i -pnginx --no-restart-on-upgrade --no-start --name=nginx
+	dh_systemd_enable -pnginx --name=nginx nginx.service
 	sed -e 's/%%PROVIDES%%/nginx-debug/g' \
 		-e 's/%%DEFAULTSTART%%//g' \
 		-e 's/%%DEFAULTSTOP%%/0 1 2 3 4 5 6/g' \
 		< debian/ > debian/nginx-debug.init
 	dh_installinit -i -pnginx --no-restart-on-upgrade --no-start --noscripts --name=nginx-debug
+	dh_systemd_enable -pnginx --name=nginx-debug --no-enable nginx-debug.service
 	dh_installlogrotate -i -pnginx --name=nginx

 binary-arch: install build-dbg

comment:4 by Niels Hendriks, 7 years ago

I just tested your patch and this works on my machine; after installing the deb file the nginx service is now enabled in nginx!

Thank you :-)

Version 0, edited 7 years ago by Niels Hendriks (next)

comment:5 by thresh, 7 years ago

Resolution: fixed
Status: assignedclosed

The updated package (1.13.5-2) with the fix in place is published on repositories.


Note: See TracTickets for help on using tickets.