Bug 201045

Summary: www/nginx: tmpdir removed on binary package upgrade using pkg, breaking running instance
Product: Ports & Packages Reporter: Michael Gmelin <grembo>
Component: Individual Port(s)Assignee: Sergey A. Osokin <osa>
Status: Closed FIXED    
Severity: Affects Some People CC: m.tsatsenko
Priority: --- Flags: bugzilla: maintainer-feedback? (osa)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Patch
none
Update patch grembo: maintainer-approval?

Description Michael Gmelin freebsd_committer freebsd_triage 2015-06-22 13:58:29 UTC
When upgrading nginx using pkg, NGINX_TMPDIR (usually /var/tmp/nginx) is removed. In setups relying on tmpdir this breaks the webserver (file upload, caches etc.) and therefore an immediate restart of nginx is required right after the upgrade (plus user experience might by suboptimal due to removed files).

The plist already contains a fix for portmaster (which sets UPGRADE_PORT when upgrading the port):

nginx/pkg-plist:@unexec if [ -z ${UPGRADE_PORT} ] ; then rm -fr %%NGINX_TMPDIR%%; fi

Unfortunately this doesn't help when using pkg, so pkg install will remove /var/tmp/nginx, essentially breaking the webserver.

The workaround is to set UPGRADE_PORT yourself on pkg install, e.g.:

UPGRADE_PORT=nginx pkg install nginx

This is not really user friendly though, so it might be better to simply not remove the temporary directory on pkg delete by default.
Comment 1 Sergey A. Osokin freebsd_committer freebsd_triage 2015-06-22 22:24:11 UTC
Created attachment 157995 [details]
Patch

Could you try following patch, thanks in advance.
Comment 2 Michael Gmelin freebsd_committer freebsd_triage 2015-06-25 08:50:18 UTC
Created attachment 158042 [details]
Update patch
Comment 3 Michael Gmelin freebsd_committer freebsd_triage 2015-06-25 08:51:23 UTC
This gives

"pkg-static: lstat(/usr/ports/www/nginx/work/stage/var/tmp/nginx/): No such file or directory"

on make install, adding "${MKDIR} ${STAGEDIR}${NGINX_TMPDIR}" to do-install fixes that.

I attached an updated version of the patch that adds that line.

With this it works as expected (empty /var/tmp/nginx gets removed, while populated /var/tmp/nginx stays intact).
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-06-25 21:06:55 UTC
A commit references this bug:

Author: osa
Date: Thu Jun 25 21:06:40 UTC 2015
New revision: 390602
URL: https://svnweb.freebsd.org/changeset/ports/390602

Log:
  Be more accurate with tmpdir removal and remove only empty tmpdir.
  Cause otherwise removal non-empty tmpdir breaks running nginx instance.

  Bump PORTREVISION.

  PR:		201045
  Tested by:	grembo

Changes:
  head/www/nginx/Makefile
  head/www/nginx/pkg-plist
  head/www/nginx-devel/Makefile
  head/www/nginx-devel/pkg-plist
Comment 5 Sergey A. Osokin freebsd_committer freebsd_triage 2015-06-25 21:07:25 UTC
Committed, thanks for report.
Comment 6 Jason Unovitch freebsd_committer freebsd_triage 2015-10-12 01:29:36 UTC
*** Bug 184721 has been marked as a duplicate of this bug. ***