diff --git a/build/scripts/run_main.sh b/build/scripts/run_main.sh index d728c7b25179b2d22b52dc363d7a68b32e2439ae..c3b9d14763635c032a46629f2fc1113bc02ffd97 100644 --- a/build/scripts/run_main.sh +++ b/build/scripts/run_main.sh @@ -116,7 +116,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 @@ -229,6 +229,7 @@ a500a2=n a200ia2=n quiet_flag=n ISULA=none +RESERVEDEFAULT=no while true do @@ -283,6 +284,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 058f1c6d05970718e39967a18ca4dcfb09173c37..d8f6b5b14666defc8e772e9cb3d74a59210dfa43 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 5487299cff3702632fddc64d760ebe06583b4e62..3464f3a4402835bc129230dad41ae08ce8dae3ba 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 + } +}