thin-edge.io
thin-edge.io copied to clipboard
Make the log directory path configurable by `--init` option
Is your feature request related to a problem? Please describe.
tedge_agent --init
creates /var/log/tedge/agent
directory, which is hard-coded. We have now logs.path
key in tedge config to change the part of the path /var/log
.
Describe the solution you'd like
Introduce an argument --log-dir
in tedge_agent, and create a directory <provided_path>/tedge/agent.
Usage:
tedge_agent --init --config-dir /path/to/config/dir --log-dir /path/to/log/dir
Then, /path/to/log/dir/tedge/agent
will be created.
Describe alternatives you've considered
Additional context
It comes from the PR of --config-dir
option, https://github.com/thin-edge/thin-edge.io/pull/1059#discussion_r844955524.
Sure the --init
option must create the missing directories. But why not use the logs.path
provided by the config given by --config-dir
?
Sure the
--init
option must create the missing directories. But why not use thelogs.path
provided by the config given by--config-dir
?
You're right. I'd change my solution.
When
logs.file = '/custom/log/path'
As of now:
tedge_agent --init
creates a directory /var/log/tedge/agent
.
Proposal:
tedge_agent --init
creates a directory /custom/log/path/tedge/agent
.
How to Test
Feature: logs path is configurable during tedge agent --init
Scenario: settings logs path
Given DUT has tedge and tedge_agent installed
When the logs path is changed: " sudo tedge config set logs.path /tmp"
And "sudo tedge_agent --init" is executed
Then the directories /tmp/tedge/agent are created.
extra commands:
sudo tedge config unset logs.path
sudo tedge config list --all
sudo tedge config get logs.path
Pushing issue back to "TO DO" because not functioning as described
I am getting error: by running the "When" part of the test:
pi@raspberrypi:/ $ sudo tedge config set logs.path /test
pi@raspberrypi:/ $ sudo tedge_agent --init
2022-08-26T06:40:46.390930751Z ERROR flockfile::unix: Another instance of tedge_agent is running.
2022-08-26T06:40:46.391018825Z ERROR flockfile::unix: Lock file path: /run/lock/tedge_agent.lock
Error: Couldn't acquire file lock.
Caused by:
Permission denied (os error 13)
This occurs when two instances of the tedge agent are running simultaneously. Did you have the tedge agent running by any chance?
Note, the "Given" part does not state a connection to Cumulocity is needed. If you were connected, disconnect or stop the tedge agent process sudo systemctl stop tedge-agent.service
and try again.
Again, this message you saw has nothing to do with whether the fix is working or not. Putting this back for review.
As said by @initard this is the currently expected behavior. If some agent is running in the background, then a new agent process instance will fail.
@didier-wenzek @initard I did tried with stopping the tedge agent service using sudo systemctl stop tedge-agent.service
and got the mentioned error message, and still receiving it
Mentioned test work only on device that was never connected to cloud, is this also "as expected"?
Thank's @rina23q, she found the reason for the error, here is the proper Test Case:
Feature: logs path is configurable during tedge agent --init
Scenario: settings logs path
Given DUT has tedge and tedge_agent installed
When the logs path is changed: " sudo tedge config set logs.path /tmp"
And "sudo -u tedge tedge_agent --init" is executed
Then the directories /tmp/tedge/agent are created.
Pushing this issue back to in Progress Bug created: https://github.com/thin-edge/thin-edge.io/issues/1387
#1387 is merged and the bug is fixed.