[systemd-devel] systemctl how to stop a service
liuxueping
liuxueping1 at huawei.com
Sat May 14 08:55:11 UTC 2016
Hi:
I have a test in arm64,my test case try to start/stop a ntp service
frequently,like that:
#!/bin/bash
i=0
while [ 1 ];do
echo "========$((i++))========"
systemctl restart ntpd &
kill -9 $!
sleep 10
systemctl stop ntpd
echo "stop status:$?"
systemctl start ntpd
ps aux >> file
sleep 5
ps aux >> file
status_ntpd_result=$(systemctl status ntpd.service|grep Active|awk
'{print($2)}')
if [ "${status_ntpd_result}" != "active" ]
then
echo "The status_ntpd_result is error, is not active."
ps aux |grep ntp |grep -v grep
exit 1
fi
ps aux |grep ntpd |grep -v grep
sleep 10
done
A few minutes later, the ntpd service failed to start,ant systemctl
status ntpd shows:
ntpd[6698]: unable to bind to wildcard address 0.0.0.0 - another process
may be running - EXITING
The result of "ps aux" before sleep 5 shows:
root 6698 0.0 0.0 0 0 ? Ds 08:45 0:00 [ntpd]
After 5 seconds,there is no ntpd process in system.
the stop status is 0,the execution of the stop command is successful,the
PID of the ntpd process is 1.
I would like to know if the systemctl command will wait for all the
processes to exit completely before returning the result.
More information about the systemd-devel
mailing list