thin-edge.io icon indicating copy to clipboard operation
thin-edge.io copied to clipboard

Make the log directory path configurable by `--init` option

Open rina23q opened this issue 2 years ago • 2 comments

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.

rina23q avatar Apr 11 '22 12:04 rina23q

Sure the --init option must create the missing directories. But why not use the logs.path provided by the config given by --config-dir?

didier-wenzek avatar Apr 11 '22 15:04 didier-wenzek

Sure the --init option must create the missing directories. But why not use the logs.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.

rina23q avatar Apr 12 '22 08:04 rina23q

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

cmosd avatar Aug 16 '22 06:08 cmosd

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)

gligorisaev avatar Aug 26 '22 06:08 gligorisaev

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.

cmosd avatar Aug 30 '22 14:08 cmosd

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 avatar Aug 30 '22 15:08 didier-wenzek

@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"?

gligorisaev avatar Aug 31 '22 11:08 gligorisaev

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.

gligorisaev avatar Aug 31 '22 11:08 gligorisaev

Pushing this issue back to in Progress Bug created: https://github.com/thin-edge/thin-edge.io/issues/1387

gligorisaev avatar Aug 31 '22 14:08 gligorisaev

#1387 is merged and the bug is fixed.

rina23q avatar Sep 05 '22 09:09 rina23q