nic-6443 opened a new issue, #9171:
URL: https://github.com/apache/apisix/issues/9171
### Current Behavior
When starting with a custom configuration file using `start -c`, if it exits
abnormally after two starts, an error will occur when trying to start
again:`failed to link customized config, error: File exists`
### Expected Behavior
_No response_
### Error Logs
_No response_
### Steps to Reproduce
### Reproduction steps
1. Create a `config.yaml` file.
```
etcd:
host:
- "http://127.0.0.1:22333" # An etcd service that cannot be connected to.
prefix: "/apisix"
```
2. start apisix three times using this configuration.
First time:
> [root@apisix-test-6c78bd9db9-d5qkh apisix]# apisix start -c ./config.yaml
/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua start -c
./config.yaml
Use customized yaml: ./config.yaml
Warning! Request etcd endpoint 'http://127.0.0.1:22333/version' error,
connection refused, retry time=1
Warning! Request etcd endpoint 'http://127.0.0.1:22333/version' error,
connection refused, retry time=2
request etcd endpoint 'http://127.0.0.1:22333/version' error, connection
refused
all etcd nodes are unavailable
Second time:
> [root@apisix-test-6c78bd9db9-d5qkh apisix]# apisix start -c ./config.yaml
/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua start -c
./config.yaml
Use customized yaml: ./config.yaml
Warning! Request etcd endpoint 'http://127.0.0.1:22333/version' error,
connection refused, retry time=1
Warning! Request etcd endpoint 'http://127.0.0.1:22333/version' error,
connection refused, retry time=2
request etcd endpoint 'http://127.0.0.1:22333/version' error, connection
refused
all etcd nodes are unavailable
Third time:
> [root@apisix-test-6c78bd9db9-d5qkh apisix]# apisix start -c ./config.yaml
/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua start -c
./config.yaml
**failed to link customized config, error: File exists**
### Error reason
https://github.com/apache/apisix/blob/81149cd31567f6a86e33100fa7d09d7550073157/apisix/cli/ops.lua#L806-L817
`apisix start -c` uses the `rename` system call to rename the existing
`config.yaml` to `config.yaml.bak`, and then hard links the custom
configuration to `conf/config.yaml`. After two startups, both `config.yaml` and
`config.yaml.bak` become hard links that point to same file. At this point,
executing `rename` again will have no effect.
> [If the old argument and the new argument resolve to the same existing
file, rename() shall return successfully and perform no other action.
](https://linux.die.net/man/3/rename#:~:text=If%20the%20old%20argument%20and%20the%20new%20argument%20resolve%20to%20the%20same%20existing%20file%2C%20rename()%20shall%20return%20successfully%20and%20perform%20no%20other%20action.)
This leads to the existence of both `config.yaml` and `config.yaml.bak` in
the `conf/` directory after executing `os.rename`, causing a `File exists`
error when executing `link`.
### Environment
/
--
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]