diff --git a/xCAT-rmc/xCAT-rmc.spec b/xCAT-rmc/xCAT-rmc.spec index 235d0d2da..70664eab1 100644 --- a/xCAT-rmc/xCAT-rmc.spec +++ b/xCAT-rmc/xCAT-rmc.spec @@ -103,7 +103,7 @@ fi %ifos linux if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then - /etc/init.d/xcatd restart + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd -r fi fi %else diff --git a/xCAT-server/debian/dirs b/xCAT-server/debian/dirs index 16b86efce..2171d2d80 100644 --- a/xCAT-server/debian/dirs +++ b/xCAT-server/debian/dirs @@ -35,6 +35,7 @@ opt/xcat/xdsh opt/xcat/xdsh/Context opt/xcat/ws etc/init.d +lib/systemd/system etc/xcat etc/apache2/conf-enabled etc/apache2/conf-available diff --git a/xCAT-server/debian/install b/xCAT-server/debian/install index 12d7fffa8..320403a55 100644 --- a/xCAT-server/debian/install +++ b/xCAT-server/debian/install @@ -29,6 +29,7 @@ lib/xcat/Confluent/* opt/xcat/lib/perl/Confluent/ lib/xcat/shfunctions opt/xcat/lib etc/init.d/xcatd etc/init.d +etc/init.d/xcatd.service lib/systemd/system/ xCAT-wsapi/* opt/xcat/ws/ LICENSE.html opt/xcat/share/doc/packages/xCAT-server diff --git a/xCAT-server/debian/postinst b/xCAT-server/debian/postinst index 412f721d4..537983431 100644 --- a/xCAT-server/debian/postinst +++ b/xCAT-server/debian/postinst @@ -20,15 +20,32 @@ set -e case "$1" in configure) - . /etc/profile.d/xcat.sh - update-rc.d xcatd defaults - if [ -f /tmp/xCAT-server_upgrade.tmp ]; then - if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - /etc/init.d/xcatd reload - fi - rm /tmp/xCAT-server_upgrade.tmp - fi - ln -sf /opt/xcat/sbin/xcatd /usr/sbin/xcatd + . /etc/profile.d/xcat.sh + if [ -f /tmp/xCAT-server_upgrade.tmp ]; then + if [ -x /lib/systemd/systemd ]; then + if [ -f /run/systemd/generator.late/xcatd.service ]; then + # To cover the case upgrade from no xcatd systemd unit file (cannot enable by default for HA case) + ls /etc/rc?.d/S??xcatd >/dev/null 2>&1 + if [ "$?" = "0" ]; then + [ -x /usr/sbin/update-rc.d ] && /usr/sbin/update-rc.d xcatd remove + /bin/systemctl daemon-reload + /bin/systemctl enable xcatd.service + fi + else + /bin/systemctl daemon-reload + fi + fi + # No need to reload xcatd here as it will be covered by xCAT/xCATsn now + rm /tmp/xCAT-server_upgrade.tmp + else + if [ -x /lib/systemd/systemd ]; then + /bin/systemctl daemon-reload + /bin/systemctl enable xcatd.service + else + update-rc.d xcatd defaults + fi + fi + ln -sf /opt/xcat/sbin/xcatd /usr/sbin/xcatd ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/xCAT-server/debian/postrm b/xCAT-server/debian/postrm index 4c92dbf3e..959819242 100644 --- a/xCAT-server/debian/postrm +++ b/xCAT-server/debian/postrm @@ -24,10 +24,6 @@ case "$1" in ;; remove) - if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - /etc/init.d/xcatd stop - fi - update-rc.d xcatd disable rm -f /usr/sbin/xcatd #remove the symbolic rm -f /etc/apache2/conf-enabled/xcat-ws.conf diff --git a/xCAT-server/debian/prerm b/xCAT-server/debian/prerm new file mode 100644 index 000000000..c347c6798 --- /dev/null +++ b/xCAT-server/debian/prerm @@ -0,0 +1,44 @@ +#!/bin/sh +# prerm script for xCAT-server +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `upgrade' +# * `failed-upgrade' +# * `remove' `in-favour' +# * `deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove) + if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image + systemctl stop xcatd.service + fi + systemctl disable xcatd.service + ;; + upgrade|deconfigure) + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/xCAT-server/etc/init.d/xcatd.service b/xCAT-server/etc/init.d/xcatd.service new file mode 100644 index 000000000..74cbfa1c8 --- /dev/null +++ b/xCAT-server/etc/init.d/xcatd.service @@ -0,0 +1,17 @@ +[Unit] +Description=xCAT management service +After=network.target syslog.service + +[Service] +EnvironmentFile=-/etc/sysconfig/xcat +Type=forking +PIDFile=/var/run/xcatd.pid +ExecStart=/etc/init.d/xcatd start +ExecStop=/etc/init.d/xcatd stop +LimitNOFILE=16000 +RemainAfterExit=no +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=multi-user.target diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index be5e512ca..b72a66d10 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -452,12 +452,6 @@ if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL || $::genCredentials) } else { - #since the xcatd service unit file is updated on xcat upgrade - #"systemctl daemon-reload" need to be run to update the service unit - if ($::UPDATEINSTALL) { - $xcmd="type systemctl >/dev/null 2>&1 && systemctl daemon-reload"; - xCAT::Utils->runcmd("$xcmd", 0); - } #$xcmd = "/etc/init.d/xcatd restart"; xCAT::Utils->restartservice("xcatd"); } @@ -1082,7 +1076,7 @@ sub initDB my $master; $master = xCAT::NetworkUtils->getipaddr($hname); if (!$master) { - xCAT::MsgUtils->message("E", "Hostname resolution for $hname failed, setting the site.master to NORESOLUTION for now, after the xCAT installation is finished, fix this hostname resolution problem, change the site.master to the correct value and then resart xcatd."); + xCAT::MsgUtils->message("E", "Hostname resolution for $hname failed, setting the site.master to NORESOLUTION for now, after the xCAT installation is finished, fix this hostname resolution problem, change the site.master to the correct value and then restart xcatd."); $master = "NORESOLUTION"; } diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index fd2ebd942..0a3fbf9d8 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -327,6 +327,8 @@ chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/shfunctions %else mkdir -p $RPM_BUILD_ROOT/etc/init.d cp etc/init.d/xcatd $RPM_BUILD_ROOT/etc/init.d +mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system +cp etc/init.d/xcatd.service $RPM_BUILD_ROOT/usr/lib/systemd/system %endif #TODO: the next has to me moved to postscript, to detect /etc/xcat vs /etc/opt/xcat mkdir -p $RPM_BUILD_ROOT/etc/%httpconfigdir @@ -394,6 +396,7 @@ rm -rf $RPM_BUILD_ROOT %if %fsm %else /etc/init.d/xcatd +/usr/lib/systemd/system/xcatd.service #/etc/%httpconfigdir/conf.orig/xcat-ws.conf.apache24 #/etc/%httpconfigdir/conf.orig/xcat-ws.conf.apache22 /etc/apache2/conf.d/xcat-ws.conf @@ -401,6 +404,9 @@ rm -rf $RPM_BUILD_ROOT %endif %changelog +* Fri Jul 6 2018 - Bin Xu +- Added systemd unit file + * Tue Nov 20 2007 - Jarrod Johnson - Changes for relocatible rpm. @@ -436,7 +442,10 @@ fi ln -sf $RPM_INSTALL_PREFIX0/sbin/xcatd /usr/sbin/xcatd if [ "$1" = "1" ]; then #Only if installing for the first time.. - if [ -x /sbin/chkconfig ]; then + if [ -x /usr/lib/systemd/systemd ]; then + /usr/bin/systemctl daemon-reload + /usr/bin/systemctl enable xcatd.service + elif [ -x /sbin/chkconfig ]; then /sbin/chkconfig --add xcatd elif [ -x /usr/lib/lsb/install_initd ]; then /usr/lib/lsb/install_initd /etc/init.d/xcatd @@ -446,6 +455,19 @@ if [ "$1" = "1" ]; then #Only if installing for the first time.. fi if [ "$1" -gt "1" ]; then #only on upgrade... + if [ -x /usr/lib/systemd/systemd ]; then + if [ -f /run/systemd/generator.late/xcatd.service ]; then + # To cover the case upgrade from no xcatd systemd unit file (cannot enable by default for HA case) + ls /etc/rc.d/rc?.d/S??xcatd >/dev/null 2>&1 + if [ "$?" = "0" ]; then + [ -x /sbin/chkconfig ] && /sbin/chkconfig --del xcatd + /usr/bin/systemctl daemon-reload + /usr/bin/systemctl enable xcatd.service + fi + else + /usr/bin/systemctl daemon-reload + fi + fi #migration issue for monitoring XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/chtab filename=monitorctrl.pm notification -d fi @@ -486,7 +508,9 @@ if [ $1 == 0 ]; then #This means only on -e /etc/init.d/xcatd stop fi - if [ -x /sbin/chkconfig ]; then + if [ -x /usr/lib/systemd/systemd ]; then + /usr/bin/systemctl disable xcatd.service + elif [ -x /sbin/chkconfig ]; then /sbin/chkconfig --del xcatd elif [ -x /usr/lib/lsb/remove_initd ]; then /usr/lib/lsb/remove_initd /etc/init.d/xcatd diff --git a/xCAT-test/autotest/testcase/xcatd/case0 b/xCAT-test/autotest/testcase/xcatd/case0 index 8876f1f1b..4d7fe3edd 100644 --- a/xCAT-test/autotest/testcase/xcatd/case0 +++ b/xCAT-test/autotest/testcase/xcatd/case0 @@ -56,6 +56,9 @@ check:output=~xcatd service is running|active \(running\) cmd:service xcatd stop check:rc==0 cmd:sleep 3 +cmd:ps axjf |grep -v grep |grep "xcatd:" | wc -l +check:rc==0 +check:output=~0 cmd:service xcatd status check:output=~xcatd service|xcatd.service check:output=~xcatd service is not running|inactive \(dead\) diff --git a/xCAT-vlan/xCAT-vlan.spec b/xCAT-vlan/xCAT-vlan.spec index 487dbcb12..5554a8872 100755 --- a/xCAT-vlan/xCAT-vlan.spec +++ b/xCAT-vlan/xCAT-vlan.spec @@ -79,7 +79,7 @@ rm -rf $RPM_BUILD_ROOT %ifos linux if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then - /etc/init.d/xcatd reload + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd -r fi fi %else