View | Details | Raw Unified | Return to bug 56914
Collapse All | Expand All

(-)a/etc/init.d/samba-ad-dc (-23 / +29 lines)
Lines 77-106 Link Here
77
		log_daemon_msg "Stopping $DESC" $NAME
77
		log_daemon_msg "Stopping $DESC" $NAME
78
		## sometimes samba takes a long time to terminate,
78
		## sometimes samba takes a long time to terminate,
79
		## which would make starting new samba processes fail.
79
		## which would make starting new samba processes fail.
80
		start-stop-daemon --stop --quiet --pidfile $PIDFILE \
80
		pids="$(pgrep --exact samba$; pgrep --exact smbd$; pgrep --exact winbindd$)"
81
			--name samba --retry 'TERM/15/KILL/1' -v \
81
		start-stop-daemon --stop --quiet --pidfile $PIDFILE --name samba
82
			| sed -rn 's/.*, (retry #|refused to die)/\1/p' \
82
		ret=0
83
			| while read line; do log_action_cont_msg "$line"; done
83
		TERM_TIMEOUT=60
84
		ret="$?"
84
		KILL_TIMEOUT=10
85
		## check for smbd and winbindd as well, in case ADDS has just been configured
85
		if [ -n "$pids" ]; then
86
		for service in smbd winbindd; do
86
			unset pgids kgids
87
			pid=$(pgrep -x "$service")
87
			while read pid; do
88
			if [ -n "$pid" ]; then
88
				pgids="$pgids -g $pid"
89
				start-stop-daemon --stop --quiet --oknodo \
89
				kgids="$kgids -${pid# }"
90
					--name "$service" --retry "TERM/3/KILL/1" -v \
90
			done <<-_EOF_
91
					| sed -rn 's/.*, (retry #|refused to die)/\1/p' \
91
			$pids
92
					| while read line; do log_action_cont_msg "$line"; done
92
			_EOF_
93
			while [ $TERM_TIMEOUT -gt 0 ]; do
94
				[ -z "$(ps -o pid= $pgids)" ] && break
95
				sleep 1
96
				TERM_TIMEOUT=$((TERM_TIMEOUT-1))
97
			done
98
			if [ $TERM_TIMEOUT -eq 0 ]; then
99
				log_action_msg "Samba did not terminate in time. Killing remaining processes"
100
				ps -Ho state,pid,pgrp,time,args $pgids \
101
					| while read line; do log_action_msg "$line"; done
102
				kill -9 $kgids 2>/dev/null
103
				while [ $KILL_TIMEOUT -gt 0 ]; do
104
					[ -z "$(ps -o pid= $pgids)" ] && break
105
					sleep 1
106
					KILL_TIMEOUT=$((KILL_TIMEOUT-1))
107
				done
108
				[ $KILL_TIMEOUT -eq 0 ] && ret=1
93
			fi
109
			fi
94
		done
95
		## Check again for /usr/sbin/samba
96
		pgrep_output="$(pgrep -f /usr/sbin/samba)"
97
		if [ -n "$pgrep_output" ]; then
98
			{
99
			echo -e "ERROR: Stuck process after service stop:\n$pgrep_output"
100
			echo "PIDFILE: $(<$PIDFILE)"
101
			samba-tool processes
102
			} | logger -p daemon.error -t SAMBA
103
			pkill -9 -f /usr/sbin/samba
104
		fi
110
		fi
105
		pkill samba-dcerpcd
111
		pkill samba-dcerpcd
106
		pkill samba-bgqd
112
		pkill samba-bgqd

Return to bug 56914