Yocto: add a statement in the default service file within a recipe - yocto

I'd need to add a Restart statement within a default .service file, and was looking to an alternate solution to replacing the .service file with a custom one (which works).
The idea would be just adding the following "delta" requirement in a, e.g., ${systemd_system_unitdir}/my_service.d/override.conf file:
[Service]
Restart=always
and then adding that file in a dedicated .bbappend recipe file.
Tests so far were not successful in adding the above statements in the deployed service file (despite the "delta" conf file being correctly deployed). Is this even a possible solution?

You should be able to do that simply by echoing that entry in a do_install:append() section in you .bbappend file. Something like:
do_install:append() {
echo "[Service]\nRestart=always" >> ${D}${sysconfdir}/wpa_supplicant/...
}
You can equally use sed to find and replace that section if there is already a file inplace.
${sysconfdir} will expanded to /etc. Check this file for more defined path variables: https://git.yoctoproject.org/poky/plain/meta/conf/bitbake.conf?h=blinky

Related

Postgres initdb: How to set logging_collector=on in the generated postgressql.conf file

The default postgresql.conf file created using initdb contains the following line
#logging_collector = off # Enable capturing of stderr and csvlog
Is there anyway to force initdb itself to generate a file with
logging_collector = on
rather than set options on pg-ctl or edit the generated file.
I keep all the changes in a separate file named custom.conf
Then after initdb ran, I copy the file to the data directory and append an include directive to postgresql.conf:
cp /path/to/dir/custom.conf $PGDATA
echo include = 'custom.conf' >> $PGDATA/postgresql.conf
These steps are easily scriptable, so no manual intervention required.
Alternatively you can skip the copy step and include the config file directly from the central directory. Or you could use include_dir to include the whole directory where your custom config file is stored.
This has the added benefit (in my opinion) that I have all customizations in a single file. I don't need to go through postgresql.conf to find settings that are changed from the default.
No, there is no way to do it like that.
But you can modify the file postgresql.conf.sample in the “share” directory of the PostgreSQL installation, which is used as the blueprint for postgresql.conf during initdb.

accessing variables exported in a shell in the recepe file

I have a yocto recipe file.
However I want to set a value to the variable, by exporting a variable.
For example
I modified I added a variable in oe-init-build-env, (which calls 'svn_util')
export REPO_BRANCH_ROOT=${REPO_BRANCH_ROOT}
The REPO_BRANCH_ROOT variable is set by running a utility 'svn_util', by looking at by current branch.
Now in my recepie.bb file
SRC_URI = "\
svn://${REPO_ROOT_NO_URI}/${REPO_BRANCH_ROOT}/sample module=mymodule;protocol=protocol=http;rev=HEAD \
"
However do_fetch: fails as follows.
Fetcher failure for URL: 'svn://${REPO_ROOT_NO_URI}/${REPO_BRANCH_ROOT}/sample;module=mymodule;protocol=http;rev=HEAD'. Unable to fetch URL from any source.
How do I make .bb file to be aware of my current branch and repository uri? I do not want to hard code it in the .bb file, or local.conf file Because if the .bb file is checked in to a different branch it should work correctly across all branch.
Or to rephrase the question, How a shell exported variable be accessed in the recipe file?
Got my answer, from another post.
https://www.yoctoproject.org/docs/3.1/bitbake-user-manual/bitbake-user-manual.html#var-bb-BB_ENV_EXTRAWHITE
In this case i have to add
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE REPO_SVNREV REPO_ROOT_NO_URI REPO_BRANCH_ROOT"
In the oe-init-build-env

Run supervisord with custom configuration file from startup

I'm using this article as a source to get me half way there, but I cannot figure out how to run supervisor with a custom config file path.
When I want to run supervisor manually, I just do:
supervisord -c /home/test/_app/supervisord.conf
When I implemented the auto start up script, it runs the default supervisor config file which is located in /etc/ directory. I don't want to use that one because it separates it from the core project folder and makes it hard to maintain and keep track of.
Try this:
In /etc/rc.d/init.d/supervisord, add prog_opts variable like this:
prog_opts=" -c /home/test/_app/supervisord.conf"
prog_bin="${exec_prefix}/bin/supervisord"
Then in start() function, change the call to:
daemon $prog_bin --pidfile $PIDFILE -- $prog_opts
I was able to fix this issue by simply deleting the default supervisord.conf file and then making a sym link with that default location and my custom conf file path.

Are variables supported in logrotate configuration files?

I looked at logrotate.conf examples and everything in my /etc/logrotate.d directory. Nowhere was I able to find documentation on variables in these files.
I am trying to create a config file for rotating the logs of an application we are writing. I want to set the directory where logs are stored once, and then use it as a variable, like so:
my_app_log_dir=/where/it/is/deployed/logs
${my_app_log_dir}/*.log ${my_app_log_dir}/some_sub_dir/*.log {
missingok
# and so on
# ...
}
Is that possible?
You can achieve what you are looking for by implementing this kludge:
my-logrotate.conf ( NOTE: double quotes " are mandatory, also note that file names don't have to appear on the same line )
"*.log"
"some_sub_dir/*.log"
{
missingok
# and so on
# ...
}
Then the actual logrotate script - my-logrotate.sh
#!/bin/sh
set -eu
cd "${my_app_log_dir}"
exec logrotate /path/to/my-logrotate.conf
Now you can add logrotate.sh to your crontab.
You can use a bash "here document" to create a suitable config file on the fly, either at installation time or before running logrotate.
A bash script might look like this:
cat >rt.conf <<.
"${my_app_log_dir}/*.log" {
rotate 5
size 15k
missingok
}
.
logrotate rt.conf
Directly in the config file no (as far as my knowledge in logrotate goes).
Other solution:
Use the include option to include parts of the configuration file from a directory. This can help you if you have a package for your application, the package can leave a file in that directory containing only the entries for your app.
With logrotate 3.8.7,a test reveals that you can set and use variables in the pre-rotate and post-rotate script sections.
I tried this for a particular service log file.
postrotate
pid_file="/run/some_service/some_serviced.pid"
test -e "${pid_file}" && kill -s HUP $(cat "${pid_file}") || true
touch "${pid_file}.WAS_USED"
endscript
After running logrotate in force mode to ensure the log file was rotated and the post-rotate script executed, on looking in /run/some_service, there was an additional file "some_serviced.pid.WAS_USED", thus proving that the use of the variable worked.

using property file along with config file to be used with mxmlc

I'm trying to run mxmlc in the following manner.
mxmlc -load-config+=mycfg.xml C:\\projects\\src\\main.mxml -output myswf.swf
In the config file, I want to keep some values configurable, for example the paths of the external libraries. Is it possible to include a property file into the config file and use it as {property_name} in the config file?
Or is it possible to pass certain arguments from the command line itself that will override/replace the corresponding values in the config file, like the -D option in the ant command?
Please provide your suggestions.
From the LiveDocs for mxmlc / -load-config:
If you specify a configuration file,
you can override individual options by
setting them on the command line.