From dc53de578c949c2b5201197fed66ea34f75bdb92 Mon Sep 17 00:00:00 2001 From: LiuYuncheng <> Date: Mon, 17 Apr 2023 14:47:04 +0800 Subject: [PATCH] Match-id-50affe57e75974619278d8af0fddc1759c389014 --- build/scripts/run_main.sh | 4 ++- build/scripts/uninstall.sh | 4 ++- install/deb/src/main.go | 62 +++++++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/build/scripts/run_main.sh b/build/scripts/run_main.sh index b713cb8..b81b052 100644 --- a/build/scripts/run_main.sh +++ b/build/scripts/run_main.sh @@ -101,7 +101,7 @@ function install() SRC="${DOCKER_CONFIG_DIR}/daemon.json.${PPID}" DST="${DOCKER_CONFIG_DIR}/daemon.json" - ./ascend-docker-plugin-install-helper add ${DST} ${SRC} ${INSTALL_PATH}/ascend-docker-runtime + ./ascend-docker-plugin-install-helper add ${DST} ${SRC} ${INSTALL_PATH}/ascend-docker-runtime ${RESERVEDEFAULT} if [ "$?" != "0" ]; then echo 'create damon.json failed' exit 1 @@ -198,6 +198,7 @@ a200isoc=n a500a2=n quiet_flag=n ISULA=none +RESERVEDEFAULT=no while true do @@ -252,6 +253,7 @@ do if [ "$3" == "--ce=isula" ]; then DOCKER_CONFIG_DIR="/etc/isulad" ISULA=isula + RESERVEDEFAULT=yes else echo "ERROR :Please check the parameter of --ce=" exit 1 diff --git a/build/scripts/uninstall.sh b/build/scripts/uninstall.sh index 058f1c6..d8f6b5b 100644 --- a/build/scripts/uninstall.sh +++ b/build/scripts/uninstall.sh @@ -20,9 +20,11 @@ LOG_FILE="/var/log/ascend-docker-runtime/installer.log" echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "start uninstall" echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "start uninstall" >>${LOG_FILE} ROOT=$(cd $(dirname $0); pwd)/.. +RESERVEDEFAULT=no if [ "$*" == "isula" ] ; then DST='/etc/isulad/daemon.json' echo "[INFO]: You will recover iSula's daemon" + RESERVEDEFAULT=yes else DST='/etc/docker/daemon.json' echo "[INFO]: You will recover Docker's daemon" @@ -35,7 +37,7 @@ if [ ! -f "${DST}" ]; then exit 0 fi -${ROOT}/ascend-docker-plugin-install-helper rm ${DST} ${SRC} +${ROOT}/ascend-docker-plugin-install-helper rm ${DST} ${SRC} ${RESERVEDEFAULT} if [ "$?" != "0" ]; then echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "ERROR: del damon.json failed" echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "ERROR: del damon.json failed" >>${LOG_FILE} diff --git a/install/deb/src/main.go b/install/deb/src/main.go index 5487299..3464f3a 100644 --- a/install/deb/src/main.go +++ b/install/deb/src/main.go @@ -31,7 +31,7 @@ import ( "mindxcheckutils" ) -const template = `{ +const commonTemplate = `{ "runtimes": { "ascend": { "path": "%s", @@ -41,13 +41,22 @@ const template = `{ "default-runtime": "ascend" }` +const noDefaultTemplate = `{ + "runtimes": { + "ascend": { + "path": "%s", + "runtimeArgs": [] + } + } +}` + const ( actionPosition = 0 srcFilePosition = 1 destFilePosition = 2 runtimeFilePosition = 3 - rmCommandLength = 3 - addCommandLength = 4 + rmCommandLength = 4 + addCommandLength = 5 addCommand = "add" maxCommandLength = 65535 logPath = "/var/log/ascend-docker-runtime/installer.log" @@ -55,6 +64,8 @@ const ( maxFileSize = 1024 * 1024 * 10 ) +var reserveDefaultRuntime = false + func main() { ctx, _ := context.WithCancel(context.Background()) if err := initLogModule(ctx); err != nil { @@ -97,6 +108,19 @@ func initLogModule(ctx context.Context) error { return nil } +func checkParamAndGetBehavior(action string, command []string) (bool, string) { + correctParam, behavior := false, "" + if action == addCommand && len(command) == addCommandLength { + correctParam = true + behavior = "install" + } + if action == rmCommand && len(command) == rmCommandLength { + correctParam = true + behavior = "uninstall" + } + return correctParam, behavior +} + func process() (error, string) { const helpMessage = "\tadd \n" + "\t rm \n" + @@ -111,16 +135,9 @@ func process() (error, string) { if len(command) == 0 { return fmt.Errorf("error param"), "" } - action, behavior := command[actionPosition], "" - correctParam := false - if action == addCommand && len(command) == addCommandLength { - correctParam = true - behavior = "install" - } - if action == rmCommand && len(command) == rmCommandLength { - correctParam = true - behavior = "uninstall" - } + + action := command[actionPosition] + correctParam, behavior := checkParamAndGetBehavior(action, command) if !correctParam { return fmt.Errorf("error param"), "" } @@ -145,6 +162,8 @@ func process() (error, string) { runtimeFilePath = command[runtimeFilePosition] } + setReserveDefaultRuntime(command) + // check file permission writeContent, err := createJsonString(srcFilePath, runtimeFilePath, action) if err != nil { @@ -166,7 +185,11 @@ func createJsonString(srcFilePath, runtimeFilePath, action string) ([]byte, erro } } else if os.IsNotExist(err) { // not existed - writeContent = []byte(fmt.Sprintf(template, runtimeFilePath)) + if !reserveDefaultRuntime { + writeContent = []byte(fmt.Sprintf(commonTemplate, runtimeFilePath)) + } else { + writeContent = []byte(fmt.Sprintf(noDefaultTemplate, runtimeFilePath)) + } } else { return nil, err } @@ -222,7 +245,9 @@ func modifyDaemon(srcFilePath, runtimeFilePath, action string) (map[string]inter if _, ok := ascendConfig["runtimeArgs"]; !ok { ascendConfig["runtimeArgs"] = []string{} } - daemon["default-runtime"] = "ascend" + if !reserveDefaultRuntime { + daemon["default-runtime"] = "ascend" + } } else if action == rmCommand { if runtimeConfigOk { delete(runtimeConfig, "ascend") @@ -264,3 +289,10 @@ func loadOriginJson(srcFilePath string) (map[string]interface{}, error) { } return daemon, nil } + +func setReserveDefaultRuntime(command []string) { + reserveCmdPostion := len(command) - 1 + if command[reserveCmdPostion] == "yes" { + reserveDefaultRuntime = true + } +} -- Gitee