variable in supervisor config file - templates

I want to avoid "code duplication" in my supervisor config file.
In short supervisor has to launch a script with two parameters that are very similar:
command=my_script --param1=/path/to/bar.txt --param2=/path/to/foo.txt
I want to avoid the duplication of path/to.
I tried
[program:my_program]
PATHTO="/path/to"
command=my_script --param1=%(ENV_PATHTO)sbar.txt --param2=%(ENV_PATHTO)sfoo.txt
I've tried some variations with environment=PATHTO="/path/to", ${PATHTO}, etc.
Nothing seems to work.
Questions :
how to define variables in a supervisor config file ?
Is there a concept of "template" config file ?

According to file format section in document:
http://supervisord.org/configuration.html?#file-format
environment variables that are present in the environment at the time that supervisord is started can be used in the configuration file using the Python string expression syntax %(ENV_X)s.
and variables in environment=PATHTO="/path/to" will be inherited by child processes. This does not change the environment of supervisord itself.
http://supervisord.org/configuration.html?#supervisord-section-values

Related

Terraform.tfvars file not considered when calling local module in Terraform

I have parent directory from there i am calling local module ,but Terraform.tfvars file present in parent directory not considered when calling local module .Its taking values from variable file present in local module.
my code is available in GitHub. My code is working fine except that its not considering terraform.tfvars file. Can anyone let me know what is issue in this code ?
https://github.com/sammouse/terraform-code.git
Its taking values from variable file present in local module.
That's how it works. There is no inheritance of variables in TF. You have to explicitly pass all the variables in parent module when to the child module. Otherwise, you have to copy-and-paste all veriables in tfvars in parent module, to tfvars file in child module.

Dynamically loading module and dynamically calling function in that module; Python 2.7

I am trying to write Python 2.7 code that will
Dynamically load a list / array of modules from a config file at startup
Call functions from those modules. Those functions are also designated in a config file (maybe the same config file, maybe a different one).
The idea is my code will have no idea until startup which modules to load. And the portion that calls the functions will have no idea which functions to call and which modules those functions belong to until runtime.
I'm not succeeding. A simple example of my situation is this:
The following is abc.py, a module that should be dynamically loaded (in my actual application I would have several such modules designated in a list / array in a config file):
def abc_fcn():
print("Hello World!")
def another_fcn():
print("BlahBlah")
The following is the .py code which should load abc.py (my actual code would need to import the entire list / array of modules from the config file). Both this .py file and abc.py are in the same folder / directory. Please note comments next to each statement.
module_to_import = "abc" #<- Will normally come from config file
fcn_to_call = "abc.abc_fcn" #<- Will normally come from config file
__import__(module_to_import) #<- No error
print(help(module_to_import)) #<- Works as expected
eval(fcn_to_call)() #<- NameError: name 'abc' is not defined
When I change the second line to the following...
fcn_to_call = "abc_fcn"
...the NameError changes to "name 'abc_fcn' is not defined".
What am I doing wrong? Thanks in advance for the help!
__import__ only returns the module specified, it does not add it to the global namespace. So to accomplish what you want, save the result as a variable, and then dynamically retrieve the function that you want. That could look like
fcn_to_call = 'abc_fcn'
mod = __import__(module_to_import)
func = getattr(mod, fcn_to_call)
func()
On a side note, abc is the name of name of the Abstract Base Classes builtin Python module, although I know you were probably just using this an example.
You should assign the returning value of __import__ to a variable abc so that you can actually use it as a module.
abc = __import__(module_to_import)

Can log4j and java util logging coexist

My application uses log4j but OkHttpClient uses java util logging. So apart from log4j.properties, I created a logging.properties file with the following contents:
handlers=java.util.logging.FileHandler
.level=FINE
okhttp3.internal.http2.level=FINE
java.util.logging.FileHandler.pattern = logs/%hjava%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
I then added this to jvm params used for starting the application -Djava.util.logging.config.file="file://${BASE_DIR}/logging.properties"
But I don't see any new folders being created as indicated by the Filehandler. Any one know why?
But I don't see any new folders being created as indicated by the Filehandler. Any one know why?
The FileHandler will not create any new folders. A directory must be created before the FileHandler will create a file.
The system property requires a path to file that is located on the filesystem It will not expand system properties or environment variables by using the dollar sign syntax.
You can use a relative path based off of the working directory or you have to use an absolute path to the logging.properties. The logging properties can not be packaged inside of an archive.
If you want to work around this limitation then you want to create a custom config class and use the java.util.logging.config.class property in conjunction with the java.util.logging.config.file property. You then write a class that reads the file://${BASE_DIR}/logging.properties and performs the needed transformation into a path to a file. Then update the configuration if you are using JDK9 or newer. On older versions you need to use readConfiguration and add code to work work around limitations of the LogManager

Vagrant - Chef - templatefile check

how do I get it out to test whether there is a template file.
I want to load the webserver default.conf.erb only if there is no other appropriate config there.
I had thought so, but without success.
template "#{node[:nginx][:dir]}/sites-available/#{host_name}.loc.conf" do
variables attribs
if File.exists? ("/templates/default/#{host_name}.conf.erb")
source "#{host_name}.conf.erb"
else
source "default.conf.erb"
end
notifies :reload, "service[nginx]"
end
Such a concept (under the label of File Specificity) is already implemented in chef.
Just place your file in templates/host-#{host_name}/ instead of templates/default/.

Save file settings in ini instead of registry

I'm new to MFC, once I create my first app, in myApp::InitInstance() . I have
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Can I delete this and save settings to my own ini construct ?
Edit: After further testing, the solution below does not work if your app class is derived from CWinAppEx ! It does work if your app is directly derived from CWinApp.
To store values in an .ini file instead of the registry:
Omit the call to SetRegistryKey.
In your app class, set m_pszProfileName to the full path of your .ini file. The filename string must be allocated using malloc, because the framework will call free on it when your app shuts down. First free the existing value, then assign your new string:
free((void*)m_pszProfileName);
m_pszProfileName = ::_tcsdup(_T("C:\\somedir\\myini.ini"));
Call CWinApp::GetProfileInt, CWinApp::WriteProfileInt and similar functions as usual.
I strongly recommend using a path under APPDATA for storing your .ini file.
Yes you can. CWinApp::SetProfileXXX() does this for you, actually - but I wouldn't use these methods anymore in 2010, they were OK when ppl moved from .ini to the registry.
I am not sure if this is possible as a .ini file has only strings for your program. You can create an operating system script (.bat for windows, .sh for unix etc) and call it using system() call.
Use win32 APIs WriteProfileString (write to INI file) and GetProfileString (read from INI file)
For more help
ms-help://MS.MSDNQTR.v90.en/sysinfo/base/writeprofilestring.htm