[vdradmin-am] Make systemd migration more robust. Apply upstreamed non-forked logging improvement patches. Run dae

Ville Skyttä scop at fedoraproject.org
Sat Jul 30 09:47:49 UTC 2011


commit 818a3b9d46c4abf8a5093f49a2911d9d94481382
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Sat Jul 30 12:47:31 2011 +0300

    Make systemd migration more robust.
    Apply upstreamed non-forked logging improvement patches.
    Run daemon in non-forked mode, direct stdout/stderr to syslog.

 vdradmin-am-3.6.8-logging.patch |  113 +++++++++++++++++++++++++++++++++++++++
 vdradmin-am-3.6.8-piddir.patch  |   21 +++++++
 vdradmin-am-tmpfiles.conf       |    1 -
 vdradmin-am.spec                |   51 +++++++++++-------
 vdradmind.service               |    6 +-
 5 files changed, 168 insertions(+), 24 deletions(-)
---
diff --git a/vdradmin-am-3.6.8-logging.patch b/vdradmin-am-3.6.8-logging.patch
new file mode 100644
index 0000000..fcaa566
--- /dev/null
+++ b/vdradmin-am-3.6.8-logging.patch
@@ -0,0 +1,113 @@
+From 9b5f54cf75c0f36b60c917ef695cda5891c9f7b6 Mon Sep 17 00:00:00 2001
+From: Ville Skyttä
+Date: Fri, 29 Jul 2011 21:47:47 +0000
+Subject: Rework non-forked logging.
+
+It is now possible to log to something else besides stderr in --nofork
+mode which now honors the config file (useful when running under a
+process supervisor such as systemd), and the new --logfile option can
+be used to override config.
+---
+diff --git a/vdradmind.pl b/vdradmind.pl
+index f49d9e9..5327bf7 100755
+--- a/vdradmind.pl
++++ b/vdradmind.pl
+@@ -264,7 +264,7 @@ my $SERVERVERSION = "vdradmind/$VERSION";
+ my %ERROR_MESSAGE;
+ my $MY_ENCODING = '';
+ 
+-my ($TEMPLATEDIR, $TEMPLATECACHE, $CONFFILE, $LOGDIR, $LOGLEVEL, $PIDFILE, $AT_FILENAME, $DONE_FILENAME, $BL_FILENAME, $ETCDIR, $CERTSDIR, $USER_CSS);
++my ($TEMPLATEDIR, $TEMPLATECACHE, $CONFFILE, $LOGGING, $LOGDIR, $LOGFILE, $LOGLEVEL, $PIDFILE, $AT_FILENAME, $DONE_FILENAME, $BL_FILENAME, $ETCDIR, $CERTSDIR, $USER_CSS);
+ if (!$SEARCH_FILES_IN_SYSTEM) {
+     $ETCDIR        = "${BASENAME}";
+     $CERTSDIR      = "${ETCDIR}/certs";
+@@ -327,7 +327,7 @@ for (my $i = 0 ; $i < scalar(@ARGV) ; $i++) {
+         $DAEMON = 0;
+         print("Usage $EXENAME [OPTION]...\n");
+         print("A perl client for the Linux Video Disk Recorder.\n\n");
+-        print("  -n         --nofork            don't fork, log to stderr\n");
++        print("  -n         --nofork            don't fork\n");
+         print("  -c         --config            run configuration dialog\n");
+         print("  -d [dir]   --cfgdir [dir]      use [dir] for configuration files\n");
+         print("  -k         --kill              kill a forked vdradmind[.pl]\n");
+@@ -335,6 +335,7 @@ for (my $i = 0 ; $i < scalar(@ARGV) ; $i++) {
+         print("  -6         --ipv6              use IPv6\n");
+         print("  -s         --ssl               only accept https:// connections\n");
+         print("  -l [level] --log [level]       set log level for this session [0 - 7]\n");
++        print("  -L [file]  --logfile [file]    set log file for this session\n");
+         print("  -h         --help              this message\n");
+         print("\nReport bugs to <mail\@andreas.vdr-developer.org>.\n");
+         exit(0);
+@@ -408,6 +409,17 @@ for (my $i = 0 ; $i < scalar(@ARGV) ; $i++) {
+     }
+     if (/^(--log|-l)/) {
+         $LOGLEVEL = $ARGV[ ++$i ];
++        $LOGGING = 1;
++        next;
++    }
++    if (/^(--logfile|-L)/) {
++        $LOGFILE = $ARGV[ ++$i ];
++        if ($LOGFILE =~ m|/|) {
++            ($LOGDIR, $LOGFILE) = $LOGFILE =~ m|^(.+)/([^/]*)$|;
++        } else {
++            $LOGDIR = ".";
++        }
++        $LOGGING = 1;
+         next;
+     }
+     if (/^(--displaycall|-i)/) {
+@@ -444,6 +456,10 @@ if ($UseIPv6) {
+ }
+ 
+ ReadConfig();
++
++$LOGGING ||= $CONFIG{LOGGING};
++$LOGFILE ||= $CONFIG{LOGFILE};
++
+ LoadTranslation();
+ 
+ #use Template::Constants qw( :debug );
+@@ -491,7 +507,7 @@ if ($@) {
+ # ---- End new template section ----
+ 
+ my $LOG_TO_SYSLOG = 0;
+-if ($DAEMON && $CONFIG{LOGGING} && $CONFIG{LOGFILE} eq "syslog") {
++if ($LOGGING && $LOGFILE eq "syslog") {
+     eval {
+         require Sys::Syslog;
+         Sys::Syslog->import(qw(:standard));
+@@ -3616,8 +3632,7 @@ sub UptoDate {
+ 
+ sub Log {
+     if ($#_ >= 1) {
+-        # Logging is always on in non-daemon mode
+-        return 1 unless ($CONFIG{LOGGING} || !$DAEMON);
++        return 1 unless $LOGGING;
+ 
+         my $level = shift;
+         chomp(my $message = join("", @_));
+@@ -3626,19 +3641,16 @@ sub Log {
+         $my_loglevel = $LOGLEVEL if defined $LOGLEVEL;
+         if ($my_loglevel >= shift @$level) {
+ 
+-            # Always log to stderr in non-daemon mode
+-            my $logfile = $DAEMON ? $CONFIG{LOGFILE} : "stderr";
+-
+             if ($LOG_TO_SYSLOG) {
+                 syslog(shift @$level, '%s', $message);
+-            } elsif ($logfile eq "stderr" || $logfile eq "syslog") {
++            } elsif ($LOGFILE eq "stderr" || $LOGFILE eq "syslog") {
+                 printf STDERR "%s: %s\n", my_strftime("%x %X"), $message;
+             } else {
+-                if (open(LOGFILE, ">>", "$LOGDIR/$logfile")) {
++                if (open(LOGFILE, ">>", "$LOGDIR/$LOGFILE")) {
+                     printf LOGFILE "%s: %s\n", my_strftime("%x %X"), $message;
+                     close(LOGFILE);
+                 } else {
+-                    printf STDERR "%s: %s\n", my_strftime("%x %X"), "Could not open log file '$LOGDIR/$logfile' for writing: $!";
++                    printf STDERR "%s: %s\n", my_strftime("%x %X"), "Could not open log file '$LOGDIR/$LOGFILE' for writing: $!";
+                 }
+             }
+         }
+--
+cgit v0.9.0.2-39-g756e
diff --git a/vdradmin-am-3.6.8-piddir.patch b/vdradmin-am-3.6.8-piddir.patch
new file mode 100644
index 0000000..b72eb48
--- /dev/null
+++ b/vdradmin-am-3.6.8-piddir.patch
@@ -0,0 +1,21 @@
+From 10e18ae583228bbfe5eb066a4a237ac67238892e Mon Sep 17 00:00:00 2001
+From: Ville Skyttä
+Date: Fri, 29 Jul 2011 21:52:36 +0000
+Subject: Do not require pid dir to exist when not running as a daemon.
+
+---
+diff --git a/vdradmind.pl b/vdradmind.pl
+index 5327bf7..1977208 100755
+--- a/vdradmind.pl
++++ b/vdradmind.pl
+@@ -784,7 +784,7 @@ sub check_permissions {
+     check_rw_dir($CERTSDIR) if ($UseSSL);
+     check_rw_dir($TEMPLATECACHE) or $rc = 0;
+     check_rw_dir($LOGDIR) or $rc = 0;
+-    check_rw_file($PIDFILE) or $rc = 0;
++    check_rw_file($PIDFILE) or $rc = 0 if $DAEMON;
+     check_rw_file($CONFFILE) or $rc = 0;
+ 
+     if ($CONFIG{AT_FUNC} || $FEATURES{AUTOTIMER}) {
+--
+cgit v0.9.0.2-39-g756e
diff --git a/vdradmin-am.spec b/vdradmin-am.spec
index 8c33779..3d7ab71 100644
--- a/vdradmin-am.spec
+++ b/vdradmin-am.spec
@@ -2,9 +2,11 @@
 %define configdir %(vdr-config --configdir 2>/dev/null || echo ERROR)
 %define videodir  %(vdr-config --videodir  2>/dev/null || echo ERROR)
 
+%global migrfile %{_var}/run/systemd-migr_%{name}-%{version}-%{release}.%{arch}
+
 Name:           vdradmin-am
 Version:        3.6.8
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Web interface for VDR
 
 Group:          Applications/Internet
@@ -15,8 +17,11 @@ Source0:        http://andreas.vdr-developer.org/download/%{name}-%{version}.tar
 Source1:        vdradmind.service
 Source2:        %{name}-httpd.conf
 Source3:        %{name}.rwtab
-Source4:        %{name}-tmpfiles.conf
 Patch0:         %{name}-3.6.6-config.patch
+# http://projects.vdr-developer.org/git/vdradmin-am.git/commit/?id=9b5f54c
+Patch1:         %{name}-3.6.8-logging.patch
+# http://projects.vdr-developer.org/git/vdradmin-am.git/commit/?id=10e18ae
+Patch2:         %{name}-3.6.8-piddir.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildArch:      noarch
@@ -30,12 +35,10 @@ BuildRequires:  systemd-units
 Requires:       perl(Locale::gettext)
 Requires:       perl(Sys::Syslog)
 Requires:       perl(Template::Plugin::JavaScript)
-Requires(pre):  shadow-utils
+Requires(pre):  shadow-utils systemd-sysv chkconfig
 Requires(post): systemd-units
 Requires(preun): systemd-units
 Requires(postun): systemd-units
-# For triggerun
-Requires(post): systemd-sysv
 
 %description
 VDRAdmin-AM is a web interface for managing VDR.  You will need access
@@ -45,6 +48,8 @@ to a local or remote VDR install to use this package.
 %prep
 %setup -q
 %patch0
+%patch1 -p1 -F 1
+%patch2 -p1
 %{__perl} -pi -e \
   's|"/video"|"%{videodir}"| ;
    s|^(\$CONFIG\{VDRCONFDIR\}\s*=\s*")[^"]*(.*)|$1%{configdir}$2| ;
@@ -81,15 +86,7 @@ install -dm 755 $RPM_BUILD_ROOT/var/{cache,log}/vdradmin
 install -Dpm 644 %{SOURCE1} $RPM_BUILD_ROOT%{_unitdir}/vdradmind.service
 install -Dpm 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/rwtab.d/%{name}
 install -dm 500 $RPM_BUILD_ROOT/etc/pki/tls/private/vdradmin
-echo "%%defattr(-,root,root,-)" > %{name}.files
 %find_lang vdradmin
-cat vdradmin.lang >> %{name}.files
-%if 0%{?fedora} > 14 || 0%{?rhel} > 6
-install -Dpm 644 %{SOURCE4} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/tmpfiles.d/%{name}.conf
-echo "%%config(noreplace) %{_sysconfdir}/tmpfiles.d/%{name}.conf" \
-    >> %{name}.files
-%endif
 
 
 %clean
@@ -101,6 +98,13 @@ getent group vdradmin >/dev/null || groupadd -r vdradmin
 getent passwd vdradmin >/dev/null || \
 useradd -r -g vdradmin -d /var/lib/vdradmin -s /sbin/nologin \
     -c "VDR web interface" -M -n vdradmin
+rm -f %{migrfile} >/dev/null 2>&1
+if [ $1 -gt 1 ] && [ ! -e %{_unitdir}/vdradmind.service ] && \
+   [ -e %{_initddir}/vdradmind ] ; then
+    systemd-sysv-convert --save vdradmind >/dev/null 2>&1
+    chkconfig --del vdradmind >/dev/null 2>&1
+    touch %{migrfile} >/dev/null 2>&1
+fi
 exit 0
 
 %post
@@ -119,14 +123,14 @@ if [ $1 -gt 0 ] ; then
     systemctl try-restart vdradmind.service >/dev/null 2>&1 || :
 fi
 
-%triggerun -- vdradmin-am
-[ -e %{_initddir}/vdradmind ] || exit 0
-systemd-sysv-convert --save vdradmind >/dev/null 2>&1
-chkconfig --del vdradmind >/dev/null 2>&1
-systemctl try-restart vdradmind.service >/dev/null 2>&1 || :
-
+%triggerpostun -- vdradmin-am
+if [ $1 -gt 0 ] && [ -e %{migrfile} ] ; then
+    systemctl daemon-reload >/dev/null 2>&1
+    systemctl try-restart vdradmind.service >/dev/null 2>&1
+fi
+rm -f %{migrfile} >/dev/null 2>&1 || :
 
-%files -f %{name}.files
+%files -f vdradmin.lang
 %doc COPYING CREDITS FAQ HISTORY INSTALL LGPL.txt README*
 %doc contrib/*example convert.pl
 %doc %{name}-httpd.conf autotimer2searchtimer.pl
@@ -141,9 +145,16 @@ systemctl try-restart vdradmind.service >/dev/null 2>&1 || :
 %dir /var/lib/vdradmin/
 %config(noreplace) /var/lib/vdradmin/vdradmind.conf
 %dir /var/log/vdradmin/
+# For lang files
+%defattr(-,root,root,-)
 
 
 %changelog
+* Sat Jul 30 2011 Ville Skyttä <ville.skytta at iki.fi> - 3.6.8-3
+- Make systemd migration more robust.
+- Apply upstreamed non-forked logging improvement patches.
+- Run daemon in non-forked mode, direct stdout/stderr to syslog.
+
 * Wed Jun  8 2011 Ville Skyttä <ville.skytta at iki.fi> - 3.6.8-2
 - BuildRequire perl(URI).
 
diff --git a/vdradmind.service b/vdradmind.service
index b7f7a26..0efcdb8 100644
--- a/vdradmind.service
+++ b/vdradmind.service
@@ -3,10 +3,10 @@ Description=WWW interface daemon for VDR
 After=syslog.target vdr.service
 
 [Service]
-Type=forking
-ExecStart=/usr/sbin/vdradmind
-PIDFile=/var/run/vdradmin/vdradmind.pid
+ExecStart=/usr/sbin/vdradmind --nofork
 User=vdradmin
+StandardOutput=syslog
+SyslogLevel=warning
 
 [Install]
 WantedBy=multi-user.target


More information about the scm-commits mailing list