Grafana: How to assign environment variable to http_port - grafana

I am trying to run grafana but i need to specify the port using an environment variable. Currently, in the custom.ini i have
# The http port to use
http_port = 9082
how do i assign an environment variable to http_port ? It would be best if i could do it from the command line but the only command line options available are
Usage of bin\grafana-server.exe:
-config string
path to config file
-homepath string
path to grafana install/home path, defaults to working directory
-pidfile string
path to pid file
-v prints current version and exits
is there any way to assign an environment variable to the http_port?

I'm not a Windows user but I guess you can write a script (bat?) to first generate the custom.ini file filling http_port with an environment variable, then run grafana-server.exe pointing to the generated config file.

Related

How to change IP in the hosts file

I am trying to change the IP address set to a particular site in the host file.
For example :
# 123.123.123 www.google.com
# 456.456.456 www.google.com
I want to make a test that I enter Google through 123.123.123 and as the program changes and open Google through 456.456.456.
Changing the servers manually is removing the # from the beginning of the line.
I do not want to use selenium grid with some machines since any machine on another server do not have the resources for it.
I want to change this in the same machine while running through the code.
As the etc/hosts file is picked up immediately by the system without a restart you can manipulate or even completely overwrite this file during your run.
The trouble is that to edit the hosts file you need 'root' rights and you are actually changing the behaviour of your host system. In order to prevent this you might think about running in a docker environment but if that is not possible you can do something like this with root access:
/etc/hosts file
# 123.123.123 www.google.com
# 456.456.456 www.google.com
as part of your test run:
# at start of run
sed -i .bak 's/# 123.123.123/123.123.123/g' /etc/hosts
# do other tests now
# later when stuff has changed
sed -i .bak 's/123.123.123/456.456.456/g' /etc/hosts
Something like this?

ERROR chef powershell ec2

I am trying to connect to ec2 (AWS) from my powershell (windows7)
I added the following lines to the knife.rb file:
knife[:aws_access_key_id] = ENV['XXXXXX']
knife[:aws_secret_access_key] = ENV['xxxxxxxxxxxxxxxxxxxxxxxxxx']
I run for example
knife ec2 server list --region eu-west-1
but get the following:
knife : ERROR: You did not provide a valid 'AWS Access Key Id' value. At line:1 char:1
ERROR: You did ... Key Id' value.:String) [], RemoteException
ERROR: You did not provide a valid 'AWS Secret Access Key' value.
do I need to upload the knife.rb file to the server after I saved it? (how?)
where should I save my pem file and how should I use it in the commands? i tried for example:
knife ec2 server create -I ami-6e7bd919 -N MyEc2Instance -x ec2-user -r "role[webserver]" -i C:\Users\MyName\Documents\openvoip.pem --region eu-west-1
Thanks!
The knife.rb file should have the following and not as described in the question:
knife[:aws_access_key_id] = "XXXXXXXXXXXXXX"
knife[:aws_secret_access_key] = "XXXXXXXXXXXXXXXXXXXX"
I had no such ENV variables, so I set the credentials directly.
To use environment variables you have to put them first in you ~/.bashrc file:
vi ~/.bashrc
export AWS_ACCESS_KEY_ID=/home/yourname/.ec2/prodaccess
export AWS_SECRET_ACCESS_KEY=/home/yourname/.ec2/prodsecret
Save. then Source .bashrc file:
. ~/.bashrc
Run: env # to see if your new variables are propagated to environment. Then you may run your knife ec2 command
If you plan on sharing your knife.rb, you might want to keep the environment variables and setup as described under 'Many Users, Same Repo' in the docs, https://docs.getchef.com/config_rb_knife.html.
In order to use the ENV vars, use something like below as opposed to the key values that you appear to use:
knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
Then, when running knife, ensure your local environment variables are set.

psql: Init files?

In the psql documentation, I read information about variables (section advanced features), e.g. one of these variables is:
HISTSIZE
The number of commands to store in the command history. The default value is 500.
Is there a file in the home directory or somewhere else where I can configure these variables?
What syntax would I use in that file?
If you look at the Files section, you'll see this:
Files
Unless it is passed an -X or -c option, psql attempts to read and execute commands from the system-wide psqlrc file and the user's ~/.psqlrc file before starting up. (On Windows, the user's startup file is named %APPDATA%\postgresql\psqlrc.conf.) See PREFIX/share/psqlrc.sample for information on setting up the system-wide file. It could be used to set up the client or the server to taste (using the \set and SET commands).
The location of the user's ~/.psqlrc file can also be set explicitly via the PSQLRC environment setting.
So like most Unix commands, there is an RC ("Run Commands") file that you can use for configuration, the name also matches the Unix conventions of ~/.cmdrc so you want ~/.psqlrc.
The format matches the \set commands you'd use within psql itself:
\set HISTSIZE 11
for example.

How to concatenate two string environment /w env stanza in Upstart?

Here is a part of my .conf file.
env SERVICE_ROOT="/data/service_root"
env LOG_DIR="$SERVICE_ROOT/logs"
and I checked all variables with following..
echo "\n`env`" >> /tmp/listener.log 2>&1
I expect that $LOG_DIR is "/data/service_root/logs" but what I got is..
SERVICE_ROOT=/data/service_root
LOG_DIR=$SERVICE_ROOT/logs
Did I miss something?
Defined environment variable is not accessible to the Job Configuration File itself.
Upstart allows you to set environment variables which will be accessible to the jobs whose job configuration files they are defined in.
As explained in 8.2 Environment Variables:
Note that a Job Configuration File does not have access to a user's environment variables, not even the superuser. This is not possible since all job processes created are children of init which does not have a user's environment.
Defined variable $SERVICE_ROOT is accessible to defined job.
# /etc/init/test.conf
env SERVICE_ROOT="/data/service_root"
script
export LOG_DIR="$SERVICE_ROOT/logs"
# prints "LOG_DIR='/data/service_root/logs'" to system log
logger -t $0 "LOG_DIR='$LOG_DIR'"
exec /home/vagrant/test.sh >> /tmp/test.log
end script
Variable $LOG_DIR exported in script block is available for processes called within the same block.
#!/bin/bash -e
# /home/vagrant/test.sh
echo "running test.sh"
echo "\n`env`" | grep 'LOG_DIR\|SERVICE_ROOT'
After running sudo start test content of /tmp/test.log will be:
running test.sh
SERVICE_ROOT=/data/service_root
LOG_DIR=/data/service_root/logs
In syslog you will find:
Jul 16 01:39:39 vagrant-ubuntu-raring-64 /proc/self/fd/9: LOG_DIR='/data/service_root/logs'

Windows Batch error: "'ping' is not recognized as an internal or external command operable program or batch file."

I am trying to run this command in windows:
ping -n 5 127.0.0.1 > nul
I get the error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Why can't windows find ping? Here is my script where it does not work:
#ECHO OFF
::set path
SET path=M:\\5.bmp
:findfile
IF EXIST %path% (
ECHO File found
) ELSE (
ECHO File not found
ping -n 5 127.0.0.1 > nul
goto findfile
)
You have overridden the PATH environment variable, so the command processor can no longer find the ping executable.
The fix is nice and simple - just use a different variable name!
:: set path
SET MyPath=M:\\5.bmp
:findfile
IF EXIST %MyPath% (
Please note that if you genuinely wanted to set the path environment variable, you should append to it like so:
REM Set temporarily for this session
SET PATH=%PATH%;C:\Some\Folder
REM Set permanently (but note - this change will not be made to this session)
SETX PATH=%PATH%;C:\Some\Folder
Hi to fix "ping" please follow below steps
Go to Properties in My computer
Advanced system settings ----->Advanced -----> Environment Variables
Select 'PATH' from the list of system variables and edit and set PATH to c:\windows\system32 ; this will solve your problem.
-----> if still u have a problem, do the below steps...
Control Panel --> System and security --> Windows Firewall --> Advanced settings --> Inbound rules --> New rule --> custom rule
in Protocol and ports: Protocol: ICMPv4
on the same panel go to customize, choose "Specific ICMP types", check the box "echo request"
The rest is trivial; go to next... next... and save it.
You should be done. This box responds ping from this point on.
Cheers
Prasad
How to diagnose this error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Because your path environment variable does not contain the directory that points to the executable: ping.exe. So the question becomes why can't your command line program cmd.exe locate ping.exe?
You can print out your path variable on the commandline like this:
echo %PATH%
Which prints for me:
C:\WINDOWS;C:\WINDOWS\system32;C:\Program Files\jZip;C:\MinGW\bin
The above string is delimited by semicolons(;). Notice the element called: C:\WINDOWS\System32, that is the element that defines where ping.exe can be located.
Solutions
You didn't specify C:\WINDOWS\System32 in your path variable. Make sure it is there.
ping.exe is missing. Find out who deleted it and put it back.
ping.exe is corrupt. Run it where it sits: C:\WINDOWS\System32\ping.exe, or replace ping.exe.
You have overridden the PATH variable before you look for it.