monkeyDluffy6017 commented on code in PR #9521:
URL: https://github.com/apache/apisix/pull/9521#discussion_r1260038026


##########
apisix/cli/ops.lua:
##########
@@ -807,17 +807,19 @@ local function start(env, ...)
         local local_conf_path = profile:yaml_path("config")
         local local_conf_path_bak = local_conf_path .. ".bak"
 
-        local ok, err = os_rename(local_conf_path, local_conf_path_bak)
-        if not ok then
-            util.die("failed to backup config, error: ", err)
-        end
-        local ok, err1 = lfs.link(customized_yaml, local_conf_path)
-        if not ok then
-            ok, err = os_rename(local_conf_path_bak,  local_conf_path)
+        if not pl_path.exists(local_conf_path_bak) then
+            local ok, err = os_rename(local_conf_path, local_conf_path_bak)
             if not ok then
-                util.die("failed to recover original config file, error: ", 
err)
+                util.die("failed to backup config, error: ", err)
+            end
+            local ok, err1 = lfs.link(customized_yaml, local_conf_path)
+            if not ok then
+                ok, err = os_rename(local_conf_path_bak,  local_conf_path)
+                if not ok then
+                    util.die("failed to recover original config file, error: 
", err)
+                end
+                util.die("failed to link customized config, error: ", err1)
             end
-            util.die("failed to link customized config, error: ", err1)
         end

Review Comment:
   The pr is not right, what i want to say is that *when starting APISIX fails, 
recover the config.yaml file*.  
   We can do like this:
   ```
       if env.deployment_role ~= "data_plane" then
           local err = init_etcd(env, args)
           if err then
               cleanup()
               util.die(err)
           end
       end
   ```
   Now we die in the `init_etcd` with no returns, so we should modify the 
`init_etcd` function to make sure the it returns the error msg instead of just 
crashing!
   The key point is `cleanup()`
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to