Telegraf service doesn't see config directory

OS - Debian 12 Bookworm Bare Metal
Telegraf version - 1.29.1

Issue - Telegraf.service fails. But “telegraf” in terminal works.

I confirm that I cannot find this isse being discussed elsewhere

Description -
I inistalled telegraf by adding the respository and using apt install. This creates a default service file in /lib/systemd/system called telegraf.service. This service file calls telegraf with the following command ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS

In my particular case, I don’t have a config file called telegraf.conf in /etc/telegraf. Instead I have “abcd.conf” inside /etc/telegraf/telegraf.d (the default telegraf config directory).

Expected Behaviour -

sudo systemctl start telegraf.service

telegraf finds abcd.conf inside /etc/telegraf/telegraf.d and uses the values given inside that config file.

Actual Behaviour -
telegraf.service fails and restarts with journalctl giving the error “no file/directory found at /etc/telegraf/telegraf.conf”

However running telegraf directly from the terminal as

telegraf

or

telegraf --test

works as expected with telegraf being able to find abcd.conf inside the config directory and use it to push data to my influxdb database.

WorkAround -

The workaround here is to edit /lib/systemd/system/telegraf.service such that the config file is removed and only the config directory remains and ExecStart looks like this

ExecStart=/usr/bin/telegraf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS

While it isn’t difficult to do this, I am unable to understand why the service file is unable to look inside the config directory but telegraf from the terminal is able to.

My understanding is that telegraf checks both for the default config file and the config files inside the directory and if any one is found, it uses that. However, here the service is expecting the default telegraf.conf file to be present, before searching inside the telegraf.d directory.

Any insight into this is appreciated.

Thank you,
alphamike-1612

-config /etc/telegraf/telegraf.conf

Because the service file says “hey load this config file”, you need to have the file. Otherwise, we error because you told us to load something, but we cannot.