[trytond] convert from initscript to systemd unit and use the unit file for Fedora >= 17

Dan Horák sharkcz at fedoraproject.org
Tue Jun 5 19:49:59 UTC 2012


commit 5ae03589912e99e03c5c7a5975ac6cd98550de1e
Author: Dan Horák <dan at danny.cz>
Date:   Tue Jun 5 21:49:55 2012 +0200

    convert from initscript to systemd unit and use the unit file for Fedora >= 17

 trytond.service |   32 +++++++++++++++++++++++++
 trytond.spec    |   70 +++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 85 insertions(+), 17 deletions(-)
---
diff --git a/trytond.service b/trytond.service
new file mode 100644
index 0000000..a65c20a
--- /dev/null
+++ b/trytond.service
@@ -0,0 +1,32 @@
+# It's not recommended to modify this file in-place, because it will be
+# overwritten during package upgrades.  If you want to customize, the
+# best way is to create a file "/etc/systemd/system/trytond.service",
+# containing
+#	.include /lib/systemd/system/trytond.service
+#	...make your changes here...
+# For more info about custom unit files, see
+# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
+
+# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
+# though /lib/... will still work.
+
+[Unit]
+Description=Tryton server
+After=syslog.target
+
+[Service]
+Type=simple
+User=tryton
+Group=tryton
+PIDFile=/var/lib/trytond/trytond.pid
+
+ExecStart=/usr/bin/trytond --config /etc/trytond.conf --pidfile=/var/lib/trytond/trytond.pid --logfile=/var/log/trytond/trytond.log
+
+# Give a reasonable amount of time for the server to start up/shut down
+TimeoutSec=300
+
+# We rely on systemd to restart trytond if it dies
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/trytond.spec b/trytond.spec
index 1dd5c23..f9be4cf 100644
--- a/trytond.spec
+++ b/trytond.spec
@@ -2,11 +2,15 @@
 
 %{!?_initddir: %global _initddir %{_initrddir}}
 
+%if 0%{?fedora} >= 17
+%global with_systemd 1
+%endif
+
 %global major 2.4
 
 Name:           trytond
 Version:        2.4.1
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Server for the Tryton application framework
 
 Group:          System Environment/Daemons
@@ -15,12 +19,15 @@ URL:            http://www.tryton.org
 Source0:        http://downloads.tryton.org/%{major}/%{name}-%{version}.tar.gz
 Source10:       %{name}.init
 Source11:       %{name}.sysconfig
-BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+Source20:       %{name}.service
 
 BuildArch:      noarch
 BuildRequires:  python2-devel
 BuildRequires:  python-setuptools
 BuildRequires:  python-sphinx
+%if 0%{?with_systemd}
+BuildRequires:  systemd-units
+%endif
 
 Requires:       %{name}-server = %{version}-%{release}
 Requires:       python-lxml
@@ -31,11 +38,17 @@ Requires:       pytz
 Requires:       pyOpenSSL
 Requires:       python-dateutil
 Requires:       python-polib
+%if 0%{?with_systemd}
 Requires(pre):  shadow-utils
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%else
 Requires(post):  chkconfig
 Requires(preun): chkconfig
 Requires(preun): initscripts
 Requires(postun): initscripts
+%endif
 
 Provides:       tryton(kernel) = %{major}
 
@@ -129,54 +142,79 @@ popd
 
 
 %install
-rm -rf $RPM_BUILD_ROOT
 %{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT
 
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}
 install -p -m 640 etc/%{name}.conf $RPM_BUILD_ROOT%{_sysconfdir}
 
+%if 0%{?with_systemd}
+mkdir -p $RPM_BUILD_ROOT%{_unitdir}
+install -p -m 644 %{SOURCE20} $RPM_BUILD_ROOT%{_unitdir}/
+%else
 mkdir -p $RPM_BUILD_ROOT%{_initddir}
 install -p -m 755 %{SOURCE10} $RPM_BUILD_ROOT%{_initddir}/%{name}
 
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
 install -p -m 644 %{SOURCE11} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/%{name}
+%endif
 
 mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/{lib,log}/%{name}
 
 
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-
 %pre
 getent group tryton > /dev/null || /usr/sbin/groupadd -r tryton
 getent passwd tryton > /dev/null || /usr/sbin/useradd -r -g tryton \
        -d %{_localstatedir}/lib/%{name} -s /sbin/nologin tryton
 :
 
+%if 0%{?with_systemd}
+%post
+if [ $1 -eq 1 ] ; then
+	# Initial installation
+	/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+
+%preun
+if [ $1 -eq 0 ] ; then
+	# Package removal, not upgrade
+	/bin/systemctl --no-reload disable trytond.service > /dev/null 2>&1 || :
+	/bin/systemctl stop trytond.service > /dev/null 2>&1 || :
+fi
+
+%postun
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+	# Package upgrade, not uninstall
+	/bin/systemctl try-restart trytond.service >/dev/null 2>&1 || :
+fi
+%else
 %post
 /sbin/chkconfig --add %{name} || :
 
 %preun
 if [ "$1" -eq 0 ]; then
-        /sbin/service %{name} stop &> /dev/null
-        /sbin/chkconfig --del %{name}
+	/sbin/service %{name} stop &> /dev/null
+	/sbin/chkconfig --del %{name}
 fi
 :
 
 %postun
 if [ "$1" -ge 1 ]; then
-        /sbin/service %{name} condrestart &> /dev/null || :
+	/sbin/service %{name} condrestart &> /dev/null || :
 fi
+%endif
 
 
 %files
-%defattr(-,root,root,-)
 %doc CHANGELOG COPYRIGHT INSTALL LICENSE README TODO
 %doc doc/_build/html
+%if 0%{?with_systemd}
+%{_unitdir}/%{name}.service
+%else
 %{_initddir}/%{name}
-%attr(0640,tryton,tryton) %config(noreplace) %{_sysconfdir}/%{name}.conf
 %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
+%endif
+%attr(0640,tryton,tryton) %config(noreplace) %{_sysconfdir}/%{name}.conf
 %{_bindir}/%{name}
 %{python_sitelib}/*
 %exclude %{python_sitelib}/%{name}/backend/mysql
@@ -186,26 +224,24 @@ fi
 %attr(0750,tryton,tryton) %{_localstatedir}/log/%{name}
 
 %files openoffice
-%defattr(-,root,root,-)
 
 %files webdav
-%defattr(-,root,root,-)
 
 %files mysql
-%defattr(-,root,root,-)
 %{python_sitelib}/%{name}/backend/mysql
 
 %files pgsql
-%defattr(-,root,root,-)
 %{python_sitelib}/%{name}/backend/postgresql
 
 %files sqlite
-%defattr(-,root,root,-)
 %{python_sitelib}/%{name}/backend/sqlite
 
 
 %changelog
 * Mon Jun 04 2012 Dan Horák <dan at danny.cz> - 2.4.1-1
+- convert from initscript to systemd unit and use the unit file for Fedora >= 17
+
+* Mon Jun 04 2012 Dan Horák <dan at danny.cz> - 2.4.1-1
 - new upstream version 2.4.1
 
 * Fri Mar 30 2012 Dan Horák <dan at danny.cz> - 2.2.2-1


More information about the scm-commits mailing list