diff --git a/xCAT/postscripts/remoteshell b/xCAT/postscripts/remoteshell index 82a3f6fab..0fb111bf7 100755 --- a/xCAT/postscripts/remoteshell +++ b/xCAT/postscripts/remoteshell @@ -460,15 +460,18 @@ logger -t xcat -p local4.info "start up sshd" if [[ $OSVER == ubuntu* || $OSVER == debian* ]] then - if [ ! -d /var/run/sshd ] - then - mkdir /var/run/sshd - chmod 0755 /var/run/sshd - /usr/sbin/sshd -f /etc/ssh/sshd_config - else - #service ssh restart - restartservice ssh + if [ ! -d /var/run/sshd ];then + #"/var/run/sshd": + #Contains the process ID of the sshd listening for connections + #(if there are several daemons running concurrently for different ports, + #this contains the process ID of the one started last). + #The content of this file is not sensitive; it can be world-read-able. + #prepare the "/var/run/sshd" for ubuntu + mkdir /var/run/sshd + chmod 0755 /var/run/sshd fi + #service ssh restart + restartservice ssh else #service sshd restart # sshd is not enabled on SLES 12 by default @@ -477,14 +480,12 @@ else restartservice sshd fi -# check whether the sshd daemon has been started successfully -# As we known that for rh7 the sshd cannot be started by systemctl in chroot mode -ps aux | grep -v grep | grep sshd - -if [ $? -ne 0 ]; then - if [ -e "/usr/sbin/sshd" ]; then - /usr/sbin/sshd - fi +#if the service restart with "service/systemctl" failed +#try to kill the process and start +if [ "$?" != "0" ];then + PIDLIST=`ps aux | grep -v grep | grep "/usr/sbin/sshd"|awk -F" " '{print $2}'|xargs` + [ -n "$PIDLIST" ] && kill 9 $PIDLIST + /usr/sbin/sshd fi kill -9 $CREDPID diff --git a/xCAT/postscripts/xcatlib.sh b/xCAT/postscripts/xcatlib.sh index fa238a852..de54c3f90 100755 --- a/xCAT/postscripts/xcatlib.sh +++ b/xCAT/postscripts/xcatlib.sh @@ -423,7 +423,15 @@ function startservice { return 127 fi - eval $cmd + #for the linux distributions with systemd support + #In the chrooted env, the system management commands(start/stop/restart) will be ignored and the return code is 0 + #need to return the proper code in the chrooted scenario + local retmsg + retmsg=`$cmd 2>&1` + retval=$? + [ "$retval" = "0" ] && (echo "$retmsg" | grep -i "Running in chroot,\s*ignoring request.*" >/dev/null 2>&1) && retval=1 + + return $retval } @@ -461,8 +469,16 @@ function stopservice { if [ -z "$cmd" ];then return 127 fi - - eval $cmd + + #for the linux distributions with systemd support + #In the chrooted env, the system management commands(start/stop/restart) will be ignored and the return code is 0 + #need to return the proper code in the chrooted scenario + local retmsg + retmsg=`$cmd 2>&1` + retval=$? + [ "$retval" = "0" ] && (echo "$retmsg" | grep -i "Running in chroot,\s*ignoring request.*" >/dev/null 2>&1) && retval=1 + + return $retval } @@ -499,7 +515,15 @@ function restartservice { return 127 fi - eval $cmd + #for the linux distributions with systemd support + #In the chrooted env, the system management commands(start/stop/restart) will be ignored and the return code is 0 + #need to return the proper code in the chrooted scenario + local retmsg + retmsg=`$cmd 2>&1` + retval=$? + [ "$retval" = "0" ] && (echo "$retmsg" | grep -i "Running in chroot,\s*ignoring request.*" >/dev/null 2>&1) && retval=1 + + return $retval } @@ -589,7 +613,7 @@ function enableservice { if [ -z "$cmd" ];then return 127 fi - + eval $cmd } @@ -628,7 +652,7 @@ function disableservice { if [ -z "$cmd" ];then return 127 fi - + eval $cmd } @@ -780,3 +804,4 @@ function msgutil_r { function msgutil { msgutil_r "" "$@" } +