How to set sysctl variables at CoreOS cloud-init?

Andy Shinn asked:

I’m looking for a way to set CoreOS sysctl settings during its cloud-init stage.

The CoreOS version of cloud-init only allows for a handful of configuration directives and is not the same as the regular cloud-init. For example, there is no runcmd section (see http://coreos.com/docs/cluster-management/setup/cloudinit-cloud-config/).

systemd provides a way to manage sysctl settings though files (http://www.freedesktop.org/software/systemd/man/sysctl.d.html). I am using the CoreOS cloud-init write_files section to create a file at /etc/sysctl.d/50-nf_conntrack.conf. But it won’t be picked up because the CoreOS cloud configuration happens after the sysctl.d configuration has already taken place.

Perhaps I could somehow use another systemd unit file to restart the sysctl.d unit? How could this be accomplished?

My answer:


You can simply call sysctl on the file yourself to make the settings take effect immediately, and the configuration file will be used for later reboots (if your instance is persistent).

I’d use a run command for this.

runcmd:
- sysctl -p /etc/sysctl.d/50-nf_conntrack.conf

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.