Bug 212282

Summary: sysutils/bareos-server: director fails to start on reboot with /var/run on tmpfs
Product: Ports & Packages Reporter: O. Hartmann <ohartmann>
Component: Individual Port(s)Assignee: Jose Alonso Cardenas Marquez <acm>
Status: Closed FIXED    
Severity: Affects Many People CC: ohartmann
Priority: --- Flags: bugzilla: maintainer-feedback? (acm)
Version: Latest   
Hardware: Any   
OS: Any   
Bug Depends on: 214578    
Bug Blocks: 210177    
Attachments:
Description Flags
Patch rc-scripts properly
ohartmann: maintainer-approval+
bareos-server.patch
ohartmann: maintainer-approval+
bareos-server-rc.patch
none
Patchset for making /var/run on TMPFS possible none

Description O. Hartmann 2016-08-31 12:13:04 UTC
We use /var/run bound as tmpfs, so the pidfile required by this incarnation of the bareos-server doesn't work properly:

service bareos-dir start/restart

fails silently on systems that have been rebooted after the installation of the port due to the missing folder

/var/run/bareos/

where the script files/bareos-dir.in (later residing in /usr/local/etc/rc.d/bareos-dir) expects the pidfile.

Checking the rc-script, I do not find any checks for the existence of /var/run/bareos or suitable tests for traversal.

This issue has already been dealt with by FreeBSD a long time ago since tmpfs is a possible filesystem (memory backed) even for /var/run for some security issues.

Either a proper check for the existence of the folder /var/run/bareos/ needs to be applied or the pidfile simply should be dropped into folder /var/run/ which very existence is guaranteed by FreeBSD itself.

Or I have misunderstood something.

Quick and dirty workaround:

Change /var/run/bareos/ into /var/run or explicitely set 

 bareos_dir_pidfile="/var/run/bareos-dir.9101.pid"

in /etc/rc.conf or /etc/rc.conf.local
Comment 1 O. Hartmann 2016-08-31 12:23:05 UTC
Stupid me: I forgot to mention:

/var/run needs to have proper access rights for user "bareos" under which the bareos-suite is running, so I guess the folder /var/run/bareos/ makes sense in terms it can be adjusted to the proper access rights.

In that case, a proper check of existence is necessary!
Comment 2 O. Hartmann 2016-08-31 13:46:01 UTC
Created attachment 174252 [details]
Patch rc-scripts properly

sysutils/bareos-server rc scripts lack in some checks for proper pidfile handling. See patchset.
Comment 3 O. Hartmann 2016-09-01 07:32:05 UTC
Created attachment 174279 [details]
bareos-server.patch

Refurbished rc-script for both server (bareos-dir, bareos-sd) and client (bareos-sd). Included in patch as of PR210177.
Comment 4 O. Hartmann 2016-09-01 19:12:26 UTC
Created attachment 174296 [details]
bareos-server-rc.patch

Messed up my environment and mixed too much of the patches. With this patchset, I patch only the rc-scripts that way so they provide the desired behaviour:

- check for the existence of /var/run/bareos folder, create it if necessary and apply proper ownership
Comment 5 O. Hartmann 2016-11-16 20:17:57 UTC
Created attachment 177087 [details]
Patchset for making /var/run on TMPFS possible

The patchset provided applies to Bareos 16.2.4 and obsoletes the prior version 15 pachtsets.

As the bareos-fd (file director) is considered to run with privileges root:wheel and is also considered to run as a solitair service, a special test whether user bareos exists or not is necessary when checking the existence of /var/run/bareos.

In case vareos-fd is the only service running, no user/group bareos is present and var/run/bareos has privileges root:wheel.

If uid bareos exists (probed via getent) we consider other bareos services present and mutual running. In such a case the ownership of /var/run/bareos is bareos:bareos.
Comment 6 O. Hartmann 2016-11-16 20:19:09 UTC
The provided patchset has not been able to be tested du to Bug 214578
Comment 7 commit-hook freebsd_committer freebsd_triage 2016-11-21 20:59:18 UTC
A commit references this bug:

Author: acm
Date: Mon Nov 21 20:59:11 UTC 2016
New revision: 426754
URL: https://svnweb.freebsd.org/changeset/ports/426754

Log:
  - Fix start when /var/run is on TMPFS
  - Bump PORTREVISION

  PR:		212282
  Submitted by:	O. Hartmann ohartmann (_at_) walstatt.org

Changes:
  head/sysutils/bareos-client/Makefile
  head/sysutils/bareos-client-static/Makefile
  head/sysutils/bareos-server/Makefile
  head/sysutils/bareos-server/files/bareos-dir.in
  head/sysutils/bareos-server/files/bareos-fd.in
  head/sysutils/bareos-server/files/bareos-sd.in