Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use Env variables in riemann.config - Riemann 0.3.2 #956

Closed
tarunngidwani opened this issue Sep 27, 2019 · 10 comments
Closed

Unable to use Env variables in riemann.config - Riemann 0.3.2 #956

tarunngidwani opened this issue Sep 27, 2019 · 10 comments

Comments

@tarunngidwani
Copy link

I am unable to access the value of an env variable in my riemann.config file. When I run riemann using systemctl start riemann the logs indicate that the value of the env variable is null.

I have exported the env variable and tried adding to the /etc/profile and/or /etc/environments with no luck. In the riemann.config file, I have tried accessing it directly using System/getenv and created a def to hold the env variables value.

I have attached some screenshots of setup. Any help would be much appreciated.

env-var

riemann-config

@sanel
Copy link
Contributor

sanel commented Sep 28, 2019

These env variables are not visible from init system. If you have /etc/sysconfig/riemann file (centos/rhel), you can set it there. On Ubuntu it is /etc/default/riemann.

@tarunngidwani
Copy link
Author

@sanel How do I access the variable once I set it in /etc/default/riemann? I tried (System/getenv "GRAPHITE_HOST") but that did not work and the value was still null

How does the riemann daemon know to look for variables in /etc/default/riemann on Ubuntu? I am using Systemd to start and manage the riemann daemon.

Screenshot from 2019-09-28 11-20-24

@faxm0dem
Copy link
Contributor

Can you show the output of systemctl cat riemann ?

@tarunngidwani
Copy link
Author

systemctl-cat-riemann

@faxm0dem
Copy link
Contributor

You must add an EnvironmentFile directive in the [Service] section as explained here

@sanel
Copy link
Contributor

sanel commented Sep 30, 2019

@tarunngidwani ah, systemd is ignoring this file too :S As @faxm0dem mentioned, you can use this riemann.service (you can find it in /etc/systemd/system somewhere):

[Service]
...
EnvironmentFile=-/etc/default/riemann

or set env variable directly in riemann.service:

[Service]
...
Environment="GRAPHITE_HOST=graphite-mc"

Make sure to reload systemd after editing this file.

@tarunngidwani
Copy link
Author

@sanel @faxm0dem On Ubuntu 18.04 the Systemd service file is autogenerated using the SystemV init.d system. I tried adding an env variable and exporting in /etc/init.d/riemann as such:

Screenshot from 2019-10-02 10-41-56

That did not work and the environment variable still comes up as null. Any ideas?

@sanel
Copy link
Contributor

sanel commented Oct 2, 2019

/etc/default/riemann should be read if /etc/init.d/riemann was used. Also, try to put export GRAPHITE_HOST=... in /etc/default/riemann as well.

If you are going to edit /etc/init.d/riemann, try to put GRAPHITE_HOST on top (before service was started).

@sanel
Copy link
Contributor

sanel commented Oct 2, 2019

Another approach is to have separate config.clj file (in eg /etc/riemann/files folder), where you set editable variables. For example:

;; /etc/riemann/files/config.clj
(ns files.config)
;; put all global variables here
(def GRAPHITE_HOST "graphite-mc")
;; /etc/riemann/riemann.config
(use 'files.config)

;; usual riemann.config stuff and GRAPHITE_HOST is visible here
(let [index (index)]
 ...
)

This way, you can distribute or put all /etc/riemann folder under git/hg and don't have to worry if some external variable needs to be set before service was started.

@tarunngidwani
Copy link
Author

tarunngidwani commented Oct 9, 2019

Thank you @sanel @faxm0dem for all your help. Adding the env var to /etc/default/riemann worked. The only thing that was missing was exporting the variable

For Debian-based OSs:

  • export GRAPHITE_HOST=graphite-a worked by adding it to /etc/default/riemann

For RHEL-based OSs:

  • export GRAPHITE_HOST=graphite-a worked by adding it to /etc/sysconfig/riemann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants