From 652b529119d0d016b9192ad399f7d32090250502 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 25 Nov 2015 12:21:59 -0500 Subject: [PATCH] migrate.sh: more reliably get docker pid Get the docker pid from systemd instead of grepping ps output, which can match other processes (e.g. docker clients). --- migrate.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/migrate.sh b/migrate.sh index fa364693..5ed55d11 100755 --- a/migrate.sh +++ b/migrate.sh @@ -73,6 +73,16 @@ fi } +get_docker_pid() { + if ! systemctl is-active docker >/dev/null; then + echo "Docker daemon is not running" + exit 1 + fi + + pid=$(systemctl show -p MainPID docker.service) + echo ${pid#*=} +} + container_export(){ for arg in "$@" do @@ -100,7 +110,7 @@ container_export(){ exportPath="/var/lib/atomic/migrate" fi - dockerPid=$(ps aux|grep [d]ocker|awk 'NR==1{print $2}') + dockerPid=$(get_docker_pid) dockerCmdline=$(cat /proc/$dockerPid/cmdline)||exit 1 if [[ $dockerCmdline =~ "-g=" ]] || [[ $dockerCmdline =~ "-g/" ]] || [[ $dockerCmdline =~ "--graph" ]];then if [ -z "$dockerRootDir" ] || [ $dockerRootDir = "/var/lib/docker" ];then @@ -158,7 +168,7 @@ container_import(){ importPath="/var/lib/atomic/migrate" fi - dockerPid=$(ps aux|grep [d]ocker|awk 'NR==1{print $2}') + dockerPid=$(get_docker_pid) dockerCmdline=$(cat /proc/$dockerPid/cmdline)||exit 1 if [[ $dockerCmdline =~ "-g=" ]] || [[ $dockerCmdline =~ "-g/" ]] || [[ $dockerCmdline =~ "--graph" ]];then if [ -z "$dockerRootDir" ] || [ $dockerRootDir = "/var/lib/docker" ];then