Skip to content

Commit

Permalink
migrate.sh: more reliably get docker pid
Browse files Browse the repository at this point in the history
Get the docker pid from systemd instead of grepping ps output, which can
match other processes (e.g. docker clients).
  • Loading branch information
jlebon committed Nov 26, 2015
1 parent c179489 commit 652b529
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 652b529

Please sign in to comment.