fedora-spec: added systemd post/postun/pre/preun sections
[cascardo/ovs.git] / rhel / openvswitch-fedora.spec.in
index 96b808e..f90762d 100644 (file)
@@ -92,49 +92,54 @@ make %{?_smp_mflags}
 %install
 rm -rf $RPM_BUILD_ROOT
 make install DESTDIR=$RPM_BUILD_ROOT
-install -d -m 755 $RPM_BUILD_ROOT/etc
+
 install -d -m 0755 $RPM_BUILD_ROOT%{_sysconfdir}/openvswitch
-install -p -D -m 0644 rhel/usr_lib_systemd_system_openvswitch.service \
+
+install -p -D -m 0644 \
+        rhel/usr_share_openvswitch_scripts_systemd_sysconfig.template \
+        $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/openvswitch
+install -p -D -m 0644 \
+        rhel/usr_lib_systemd_system_openvswitch.service \
         $RPM_BUILD_ROOT%{_unitdir}/openvswitch.service
-install -p -D -m 0644 rhel/usr_lib_systemd_system_openvswitch-nonetwork.service \
+install -p -D -m 0644 \
+        rhel/usr_lib_systemd_system_openvswitch-nonetwork.service \
         $RPM_BUILD_ROOT%{_unitdir}/openvswitch-nonetwork.service
-install -m 755 rhel/etc_init.d_openvswitch \
+
+install -m 0755 rhel/etc_init.d_openvswitch \
         $RPM_BUILD_ROOT%{_datadir}/openvswitch/scripts/openvswitch.init
-install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
-install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
-install -m 755 rhel/etc_logrotate.d_openvswitch \
-        $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
-install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
-install -m 644 vswitchd/vswitch.ovsschema \
-        $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
-install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
-install -d -m 0755 $RPM_BUILD_ROOT/etc/sysconfig/network-scripts/
+
+install -p -D -m 0644 rhel/etc_logrotate.d_openvswitch \
+        $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/openvswitch
+
+install -m 0644 vswitchd/vswitch.ovsschema \
+        $RPM_BUILD_ROOT/%{_datadir}/openvswitch/vswitch.ovsschema
+
+install -d -m 0755 $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/network-scripts/
 install -p -m 0755 rhel/etc_sysconfig_network-scripts_ifdown-ovs \
-        $RPM_BUILD_ROOT/etc/sysconfig/network-scripts/ifdown-ovs
+        $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/network-scripts/ifdown-ovs
 install -p -m 0755 rhel/etc_sysconfig_network-scripts_ifup-ovs \
-        $RPM_BUILD_ROOT/etc/sysconfig/network-scripts/ifup-ovs
-install -p -D -m 0644 rhel/usr_share_openvswitch_scripts_systemd_sysconfig.template \
-        $RPM_BUILD_ROOT/etc/sysconfig/openvswitch
-install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
+        $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/network-scripts/ifup-ovs
 
 install -d -m 0755 $RPM_BUILD_ROOT%{python_sitelib}
-mv $RPM_BUILD_ROOT/%{_datadir}/openvswitch/python/* $RPM_BUILD_ROOT%{python_sitelib}
+mv $RPM_BUILD_ROOT/%{_datadir}/openvswitch/python/* \
+   $RPM_BUILD_ROOT%{python_sitelib}
 rmdir $RPM_BUILD_ROOT/%{_datadir}/openvswitch/python/
 
-install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
+install -d -m 0755 $RPM_BUILD_ROOT/%{_sharedstatedir}/openvswitch
 
 install -d -m 0755 $RPM_BUILD_ROOT%{_includedir}/openvswitch
 install -p -D -m 0644 include/openvswitch/*.h \
-       -t $RPM_BUILD_ROOT%{_includedir}/openvswitch
-install -p -D -m 0644 config.h -t $RPM_BUILD_ROOT%{_includedir}/openvswitch
+        -t $RPM_BUILD_ROOT%{_includedir}/openvswitch
+install -p -D -m 0644 config.h \
+        -t $RPM_BUILD_ROOT%{_includedir}/openvswitch
 
 install -d -m 0755 $RPM_BUILD_ROOT%{_includedir}/openvswitch/lib
 install -p -D -m 0644 lib/*.h \
-       -t $RPM_BUILD_ROOT%{_includedir}/openvswitch/lib
+        -t $RPM_BUILD_ROOT%{_includedir}/openvswitch/lib
 
 install -d -m 0755 $RPM_BUILD_ROOT%{_includedir}/openflow
 install -p -D -m 0644 include/openflow/*.h \
-       -t $RPM_BUILD_ROOT%{_includedir}/openflow
+        -t $RPM_BUILD_ROOT%{_includedir}/openflow
 
 touch $RPM_BUILD_ROOT%{_sysconfdir}/openvswitch/conf.db
 touch $RPM_BUILD_ROOT%{_sysconfdir}/openvswitch/system-id.conf
@@ -153,9 +158,16 @@ touch $RPM_BUILD_ROOT%{_sysconfdir}/openvswitch/system-id.conf
 rm -rf $RPM_BUILD_ROOT
 
 %preun
-# Package removal, not upgrade
-systemctl stop openvswitch.service
-systemctl disable openvswitch.service
+%if 0%{?systemd_preun:1}
+    %systemd_preun %{name}.service
+%else
+    if [ $1 -eq 0 ] ; then
+    # Package removal, not upgrade
+        /bin/systemctl --no-reload disable %{name}.service >/dev/null 2>&1 || :
+        /bin/systemctl stop %{name}.service >/dev/null 2>&1 || :
+    fi
+%endif
+
 
 %post
 if test ! -e /etc/openvswitch/conf.db; then
@@ -170,11 +182,28 @@ if test ! -e /etc/openvswitch/conf.db; then
             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
             > /dev/null
 fi
-# Initial installation
-systemctl enable openvswitch.service
-systemctl start openvswitch.service
+
+%if 0%{?systemd_post:1}
+    %systemd_post %{name}.service
+%else
+    # Package install, not upgrade
+    if [ $1 -eq 1 ]; then
+        /bin/systemctl daemon-reload >dev/null || :
+    fi
+%endif
+
 
 %postun
+%if 0%{?systemd_postun_with_restart:1}
+    %systemd_postun_with_restart %{name}.service
+%else
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+    if [ "$1" -ge "1" ] ; then
+    # Package upgrade, not uninstall
+        /bin/systemctl try-restart %{name}.service >/dev/null 2>&1 || :
+    fi
+%endif
+
 
 %files -n python-openvswitch
 %{python_sitelib}/ovs