Unable to use Env variables in riemann.config - Riemann 0.3.2
tarunngidwani opened this issue · 10 comments
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.
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
.
@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.
Can you show the output of systemctl cat riemann
?
You must add an EnvironmentFile
directive in the [Service]
section as explained here
@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.
/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).
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.
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