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

[PROPOSAL] - Add configuration file for daemons #314

Closed
ghost opened this issue Dec 19, 2016 · 3 comments
Closed

[PROPOSAL] - Add configuration file for daemons #314

ghost opened this issue Dec 19, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 19, 2016

Hello,

Here is a proposal for configuring daemon using a file instead of specifying options on the command line.

Description

Launching the client daemon can require many options. For instance, this project, https://github.com/CreatorDev/ci40-weather-station, asks people to run
this command to launch the client daemon:

$ awa_clientd --bootstrap coaps://deviceserver.flowcloud.systems:15684 --endPointName WeatherStationDevice --certificate=/root/certificate.crt --ipcPort 12345 -p7000 -d

It would be more readable if all these options are located in a file. Each line would set only one value in this format: name(=value)?.
Using previous example, these options would be specified in a file config.cfg:

bootstrap=coaps://deviceserver.flowcloud.systems:15684
endPointName=WeatherStationDevice
certificate=/root/certificate.crt
ipcPort=12345
port=7000
daemonize

and the client would be launched in this way:

$ awa_clientd config.cfg

Implementation

I suggest to add, in the main function of all daemons, the following logic:

if argc > 1 && argv[1] matches *.cfg
    override argc and argv with content from config file

And the parsing of the configuration file would be done in daemon/src/common/config.c. It would produce an array of strings, along with the number of strings in the array.
This would be written roughly in this way:

/**
 * @param[in] filePath
 * @param[out] args 
 * @return negative number if an error occured, argc otherwise
 */
int ParseConfigurationFile(char *filePath, char **args)
{
    ret = 1
    open file in filePath
    n = number of non-empty lines

    for each line in file:
        if line is empty:
            skip
        name,value = match(line, "name(=value)?")
        args.append("--" + name)
        ret++    
        if value:
            args.append(value) 
            ret++

    return ret
}
@GonZo GonZo added this to the 0.2.6 milestone Dec 19, 2016
@GonZo GonZo changed the title Add configuration file for daemons [PROPOSAL] - Add configuration file for daemons Dec 19, 2016
@ghost ghost closed this as completed Dec 19, 2016
@DavidAntliff
Copy link
Collaborator

Just curious - why was this closed?

@ghost
Copy link
Author

ghost commented Dec 21, 2016

@DavidAntliff The option --factoryBootstrap=FILE is already doing most of what is currently suggested in this proposal.

@meowsqueak
Copy link

@francois-berder-imgtec true, for some options. Also, the systemd (or equivalent) mechanism can cover other options.

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

No branches or pull requests

3 participants