Filebeat setup command can not find environment variables

Hello @user8753123 , the reason is more around how environment variables work, and in which scope they are available.

When running commands as a user, or sudo, you do not get access to environment variables meant for the service (when it starts from systemd).

When using drop-in files or defining environment variables directly in the systemd service files, the environment variables are only available to that application for security purposes.

When you run the setup command as a user, or through sudo, it will only look for environment variables that is accessible by your user, as you are not using systemd when running setup. Which is why it only works if you add your environment variables either to /etc/profile.d or your own bash_profile file for your user.

The filebeat setup command is something you only need to run once, and should be run before the service starts up for the first time, after that you only need to run setup again on a single filebeat instance if you upgrade to a newer version and want to apply some newer changes.