已合并
提前获取mount_source避免删除后获取不到信息 #200
付阿牛创建于 6月4日
提前获取mount_source避免删除后获取不到信息 #200
已合并
付阿牛创建于 6月4日
共 2 个文件变更+16-13
@@ -777,6 +777,13 @@ container_run() {
777container_restart() {777container_restart() {
778 check_encode_card778 check_encode_card
779 779 
780+ local mount_source
781+ if [ "$DEFAULT_RUNTIME" == "docker" ]; then
782+ mount_source=$($RUNTIME_CMD inspect --format='{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' $container_name)
783+ else
784+ mount_source=$($RUNTIME_CMD inspect --mode=native --format='{{range .Spec.mounts}}{{if eq .destination "/data"}}{{.source}}{{end}}{{end}}' $container_name)
785+ fi
786+ 
780 local container_name=$1787 local container_name=$1
781 788 
782 LOG_INFO "Restart container: $container_name"789 LOG_INFO "Restart container: $container_name"
@@ -817,12 +824,6 @@ container_restart() {
817 fi824 fi
818 825 
819 local userdata_dir826 local userdata_dir
820- local mount_source
821- if [ "$DEFAULT_RUNTIME" == "docker" ]; then
822- mount_source=$($RUNTIME_CMD inspect --format='{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' $container_name)
823- else
824- mount_source=$($RUNTIME_CMD inspect --mode=native --format='{{range .Spec.mounts}}{{if eq .destination "/data"}}{{.source}}{{end}}{{end}}' $container_name)
825- fi
826 827
827 if [ -n "$mount_source" ]; then828 if [ -n "$mount_source" ]; then
828 userdata_dir=$(echo "$mount_source" | sed "s|/data/${container_name}/data$||")829 userdata_dir=$(echo "$mount_source" | sed "s|/data/${container_name}/data$||")
@@ -857,6 +858,14 @@ container_delete() {
857 LOG_INFO "Remove container: $container_name"858 LOG_INFO "Remove container: $container_name"
858 param_check_container_name "$container_name"859 param_check_container_name "$container_name"
859 860 
861+ local mount_source
862+ if [ "$DEFAULT_RUNTIME" == "docker" ]; then
863+ mount_source=$($RUNTIME_CMD inspect --format='{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' $container_name 2>/dev/null)
864+ else
865+ mount_source=$($RUNTIME_CMD inspect --mode=native --format='{{range .Spec.mounts}}{{if eq .destination "/data"}}{{.source}}{{end}}{{end}}' $container_name 2>/dev/null)
866+ fi
867+
868+ 
860 imageid="$($RUNTIME_CMD ps -a | grep $container_name | awk '{print $2}')"869 imageid="$($RUNTIME_CMD ps -a | grep $container_name | awk '{print $2}')"
861 $RUNTIME_CMD ps | grep -q "$container_name" && $RUNTIME_CMD stop -t 0 $container_name870 $RUNTIME_CMD ps | grep -q "$container_name" && $RUNTIME_CMD stop -t 0 $container_name
862 $RUNTIME_CMD rm $container_name871 $RUNTIME_CMD rm $container_name
@@ -867,12 +876,6 @@ container_delete() {
867 fi876 fi
868 877
869 local userdata_dir878 local userdata_dir
870- local mount_source
871- if [ "$DEFAULT_RUNTIME" == "docker" ]; then
872- mount_source=$($RUNTIME_CMD inspect --format='{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' $container_name 2>/dev/null)
873- else
874- mount_source=$($RUNTIME_CMD inspect --mode=native --format='{{range .Spec.mounts}}{{if eq .destination "/data"}}{{.source}}{{end}}{{end}}' $container_name 2>/dev/null)
875- fi
876 879
877 if [ -n "$mount_source" ]; then880 if [ -n "$mount_source" ]; then
878 userdata_dir=$(echo "$mount_source" | sed "s|/data/${container_name}/data$||")881 userdata_dir=$(echo "$mount_source" | sed "s|/data/${container_name}/data$||")
@@ -51,7 +51,7 @@ function check_environment() {
51 fi51 fi
52 52 
53 # 清理/dev/目录下的全部loop device节点,并在/dev/loop_device/目录下提前生成足够数量的设备节点53 # 清理/dev/目录下的全部loop device节点,并在/dev/loop_device/目录下提前生成足够数量的设备节点
54- if [ $1 == "start" ] || [ $1 == "restart" ]; then54+ if [ $1 == "start" ] || [ $1 == "nstart" ]; then
55 prepare_loop_device55 prepare_loop_device
56 fi56 fi
57 57