By default thin-edge.io persists logs under the /var/log
folder. On some devices the /var
folder is volatile, which means that the folder is newly created after each device reboot.
Normally, the folder structure under /var/log
is created by thin-edge.io during the installation process, but since the /var/log
folder is deleted, some thin-edge.io services do not function as expected.
There are two main ways to solve this problem, they are listed below.
This solution involves creating a simple systemd service which runs before the tedge-agent
service starts. The service runs the tedge-agent
initialization again (something which is normally only required once on installation).
-
Create a service file, .e.g called
/etc/systemd/system/custom-tedge-init.service
[Unit] Description=tedge init service # This is important because it tells systemd that this service # should run BEFORE tedge-agent.service! Before=tedge-agent.service [Service] Type=simple # Run the initialization of tedge-agent, so it can re-create all of the required folders ExecStart=/bin/sh -c "tedge_agent --init" [Install] WantedBy=multi-user.target
-
Enable the service so it starts on boot
systemctl enable custom-tedge-init.service
-
Test out the service by rebooting the device
shutdown -r now
-
After the device starts up, check if the custom service ran
systemctl status custom-tedge-init.service
Notes
- The above instructions are only for systemd. However the concept is the same for other service managers, so please consult the docs for your service manager for the specifics on service dependencies.
You can change the location of the log folder to a persistent folder which is not deleted after each reboot. The following example changes the default logs.path
setting to /opt/logs
.
-
Stop the tedge-agent service
sudo systemctl stop tedge-agent
-
Change the tedge path used by the default logs using
tedge config set
sudo tedge config set logs.path /opt/logs sudo mkdir -p /opt/logs/
-
Inititalize the tedge-agent folders
# Removing lock due to bug: https://github.com/thin-edge/thin-edge.io/issues/1726 sudo rm -f /run/lock/tedge*agent.lock sudo tedge_agent --init
-
Start the tedge-agent service
sudo systemctl start tedge-agent
Notes
- You will also have to update the
/etc/tedge/c8y/c8y-log-plugin.toml
file, so that any entries that refer to/var/log
to/opt/logs
(e.g. the path that you changed it to).
The following are some of the limitations of the current handlings of the files.
- Configuration management for child devices relies on the
/var/tedge/
folder for caching the files coming from the child devices and when sending to devices. So option 2 will only partially work.
Moving forward the thin-edge.io team would like to make it more configurable to be able to custom location of all files and folders.
Switched to using
tedge_agent --init
which is supported in both0.9.0
and0.8.x
tedge versions.