diff --git a/bmc-watchdog.service b/bmc-watchdog.service new file mode 100644 index 0000000..c7ada84 --- /dev/null +++ b/bmc-watchdog.service @@ -0,0 +1,12 @@ +[Unit] +Description=BMC Watchdog Timer Daemon +After=network.target + +[Service] +Type=forking +PIDFile=/run/bmc-watchdog.pid +EnvironmentFile=-/etc/sysconfig/bmc-watchdog +ExecStart=/usr/sbin/bmc-watchdog $OPTIONS + +[Install] +WantedBy=multi-user.target diff --git a/freeipmi-systemd.patch b/freeipmi-systemd.patch new file mode 100644 index 0000000..2c273ba --- /dev/null +++ b/freeipmi-systemd.patch @@ -0,0 +1,81 @@ +Fix daemon startup race. + +Accepted upstream as SVN rev. 8299 +diff -up freeipmi-1.1.1/bmc-watchdog/bmc-watchdog.c.systemd freeipmi-1.1.1/bmc-watchdog/bmc-watchdog.c +--- freeipmi-1.1.1/bmc-watchdog/bmc-watchdog.c.systemd 2012-01-02 20:26:09.000000000 +0100 ++++ freeipmi-1.1.1/bmc-watchdog/bmc-watchdog.c 2012-01-06 16:28:55.966295836 +0100 +@@ -1677,6 +1677,10 @@ _daemon_init () + unsigned int i; + pid_t pid; + FILE *pidfile; ++ int fds[2]; ++ ++ if ( pipe(fds) < 0 ) ++ _err_exit ("pipe: %s", strerror (errno)); + + if ( (pidfile = fopen(BMC_WATCHDOG_PIDFILE, "w")) == NULL ) + _err_exit ("fopen: %s", strerror (errno)); +@@ -1684,7 +1688,14 @@ _daemon_init () + if ((pid = fork ()) < 0) + _err_exit ("fork: %s", strerror (errno)); + if (pid) +- exit (0); /* parent terminates */ ++ { ++ /* parent terminates */ ++ char buf; ++ read(fds[0], &buf, 1); ++ close(fds[1]); ++ close(fds[0]); ++ exit (0); ++ } + + setsid (); + +@@ -1706,6 +1717,9 @@ _daemon_init () + + umask (0); + ++ write(fds[1], "a", 1); ++ close(fds[1]); ++ close(fds[0]); + for (i = 0; i < 64; i++) + close (i); + } +diff -up freeipmi-1.1.1/ipmidetectd/ipmidetectd.c.systemd freeipmi-1.1.1/ipmidetectd/ipmidetectd.c +--- freeipmi-1.1.1/ipmidetectd/ipmidetectd.c.systemd 2012-01-02 20:26:13.000000000 +0100 ++++ freeipmi-1.1.1/ipmidetectd/ipmidetectd.c 2012-01-06 16:28:09.309420665 +0100 +@@ -58,12 +58,22 @@ _daemon_init (void) + /* Based on code in Unix network programming by R. Stevens */ + pid_t pid; + unsigned int i; ++ int fds[2]; + ++ if (pipe(fds) < 0) ++ IPMIDETECTD_EXIT (("pipe: %s", strerror (errno))); + if ((pid = fork ()) < 0) + IPMIDETECTD_EXIT (("fork: %s", strerror (errno))); + +- if (pid != 0) /* Terminate Parent */ +- exit (0); ++ if (pid != 0) ++ { ++ /* Terminate Parent */ ++ char buf; ++ read(fds[0], &buf, 1); ++ close(fds[1]); ++ close(fds[0]); ++ exit (0); ++ } + + setsid (); + +@@ -79,6 +89,9 @@ _daemon_init (void) + chdir ("/"); + + umask (0); ++ write(fds[1], "a", 1); ++ close(fds[1]); ++ close(fds[0]); + + for (i = 0; i < 64; i++) + close (i); diff --git a/freeipmi.spec b/freeipmi.spec index 3cb0d24..9856aaa 100644 --- a/freeipmi.spec +++ b/freeipmi.spec @@ -2,7 +2,7 @@ # Copyright (c) 2003 FreeIPMI Core Team # -Release: 1%{?dist} +Release: 2%{?dist} Name: freeipmi Version: 1.1.1 @@ -10,15 +10,15 @@ License: GPLv2+ Group: Applications/System URL: http://www.gnu.org/software/freeipmi/ Source: ftp://ftp.gluster.com/pub/freeipmi/%{version}/%{name}-%{version}.tar.gz +Source1: bmc-watchdog.service +Source2: ipmidetectd.service BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -BuildRequires: libgcrypt-devel texinfo -Requires(pre): chkconfig -Requires(post): chkconfig -Requires(preun): chkconfig -# for /sbin/service -Requires(preun): initscripts -Requires(post): info -Requires(preun): info +BuildRequires: libgcrypt-devel texinfo systemd-units +Requires(preun): info systemd-units +Requires(post): info systemd-units systemd-sysv +Requires(postun): systemd-units +Patch1: freeipmi-systemd.patch + Summary: IPMI remote console and system management software %description The FreeIPMI project provides "Remote-Console" (out-of-band) and @@ -58,6 +58,7 @@ Provides a tool and a daemon for IPMI node detection. %prep %setup -q +%patch1 -p1 -b .systemd %build export CFLAGS="-D_GNU_SOURCE $RPM_OPT_FLAGS" @@ -68,19 +69,16 @@ make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make install DESTDIR="$RPM_BUILD_ROOT" -# fix coherance problems with associated script filenames -mkdir -p $RPM_BUILD_ROOT/%{_initrddir}/ -# if check needed for SLES systems -if [[ "%{_sysconfdir}/init.d" != "%{_initrddir}" ]] -then -mv $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/bmc-watchdog $RPM_BUILD_ROOT/%{_initrddir}/bmc-watchdog -mv $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/ipmidetectd $RPM_BUILD_ROOT/%{_initrddir}/ipmidetectd -fi rm -f %{buildroot}%{_infodir}/dir # kludge to get around rpmlint complaining about 0 length semephore file echo freeipmi > %{buildroot}%{_localstatedir}/lib/freeipmi/ipckey # Remove .la files rm -rf $RPM_BUILD_ROOT/%{_libdir}/*.la +# Install systemd units +install -m 755 -d $RPM_BUILD_ROOT/%{_unitdir} +install -m 644 %SOURCE1 %SOURCE2 $RPM_BUILD_ROOT/%{_unitdir}/ +# Remove initscripts +rm -rf $RPM_BUILD_ROOT/%{_initrddir} $RPM_BUILD_ROOT/%{_sysconfdir}/init.d %clean rm -rf $RPM_BUILD_ROOT @@ -97,33 +95,65 @@ fi %postun -p /sbin/ldconfig %post bmc-watchdog -/sbin/chkconfig --add bmc-watchdog +if [ $1 -eq 1 ] ; then + # Initial installation + /bin/systemctl daemon-reload >/dev/null 2>&1 || : +fi %preun bmc-watchdog -if [ "$1" = 0 ]; then - /sbin/service bmc-watchdog stop >/dev/null 2>&1 - /sbin/chkconfig --del bmc-watchdog +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + /bin/systemctl --no-reload disable bmc-watchdog.service > /dev/null 2>&1 || : + /bin/systemctl stop bmc-watchdog.service > /dev/null 2>&1 || : fi %postun bmc-watchdog -if [ "$1" -ge "1" ] ; then - /sbin/service bmc-watchdog condrestart >/dev/null 2>&1 || : +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + /bin/systemctl try-restart bmc-watchdog.service >/dev/null 2>&1 || : fi %post ipmidetectd -/sbin/chkconfig --add ipmidetectd +if [ $1 -eq 1 ] ; then + # Initial installation + /bin/systemctl daemon-reload >/dev/null 2>&1 || : +fi %preun ipmidetectd -if [ "$1" = 0 ]; then - /sbin/service ipmidetectd stop >/dev/null 2>&1 - /sbin/chkconfig --del ipmidetectd +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + /bin/systemctl --no-reload disable ipmidetectd.service > /dev/null 2>&1 || : + /bin/systemctl stop ipmidetectd.service > /dev/null 2>&1 || : fi %postun ipmidetectd -if [ "$1" -ge "1" ] ; then - /sbin/service ipmidetectd condrestart >/dev/null 2>&1 || : +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + /bin/systemctl try-restart ipmidetectd.service >/dev/null 2>&1 || : fi +%triggerun -- freeipmi-bmc-watchdog < 1.1.1-2 +# Save the current service runlevel info +# User must manually run systemd-sysv-convert --apply httpd +# to migrate them to systemd targets +/usr/bin/systemd-sysv-convert --save bmc-watchdog >/dev/null 2>&1 ||: + +# Run these because the SysV package being removed won't do them +/sbin/chkconfig --del bmc-watchdog >/dev/null 2>&1 || : +/bin/systemctl try-restart bmc-watchdog.service >/dev/null 2>&1 || : + +%triggerun -- freeipmi-ipmidetectd < 1.1.1-2 +# Save the current service runlevel info +# User must manually run systemd-sysv-convert --apply httpd +# to migrate them to systemd targets +/usr/bin/systemd-sysv-convert --save ipmidetectd >/dev/null 2>&1 ||: + +# Run these because the SysV package being removed won't do them +/sbin/chkconfig --del ipmidetectd >/dev/null 2>&1 || : +/bin/systemctl try-restart ipmidetectd.service >/dev/null 2>&1 || : + %files %defattr(-,root,root) %dir %{_sysconfdir}/freeipmi/ @@ -315,22 +345,25 @@ fi %doc %{_datadir}/doc/%{name}/COPYING.bmc-watchdog %doc %{_datadir}/doc/%{name}/DISCLAIMER.bmc-watchdog %doc %{_datadir}/doc/%{name}/DISCLAIMER.bmc-watchdog.UC -%{_initrddir}/bmc-watchdog %config(noreplace) %{_sysconfdir}/sysconfig/bmc-watchdog %config(noreplace) %{_sysconfdir}/logrotate.d/bmc-watchdog %{_sbindir}/bmc-watchdog %{_mandir}/man8/bmc-watchdog.8* +%{_unitdir}/bmc-watchdog.service %dir %{_localstatedir}/log/freeipmi %files ipmidetectd %defattr(-,root,root) -%{_initrddir}/ipmidetectd %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/freeipmi/ipmidetectd.conf %{_sbindir}/ipmidetectd %{_mandir}/man5/ipmidetectd.conf.5* %{_mandir}/man8/ipmidetectd.8* +%{_unitdir}/ipmidetectd.service %changelog +* Fri Jan 6 2012 Jan Safranek - 1.1.1-2 +- added systemd unit files (#767611) + * Wed Jan 4 2012 Jan Safranek - 1.1.1-1 - Updated to freeipmi-1.1.1: - Support new tool ipmi-pet, tool to parse/interpret platform event diff --git a/ipmidetectd.service b/ipmidetectd.service new file mode 100644 index 0000000..60f38cd --- /dev/null +++ b/ipmidetectd.service @@ -0,0 +1,10 @@ +[Unit] +Description=IPMI Node Detection Monitoring Daemon +After=network.target + +[Service] +Type=forking +ExecStart=/usr/sbin/ipmidetectd + +[Install] +WantedBy=multi-user.target