4

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?

Andy Shinn
  • 4,131
  • 8
  • 38
  • 55

3 Answers3

3

See answer on CoreOS github issue tracker: https://github.com/coreos/bugs/issues/747#issuecomment-142764415

There might be a simpler way in future, but for now you can simply write a unit to invoke systemd-sysctl during cloudinit; it'll be started after any files specified in write_files are written:

#cloud-config 
.... 
coreos:
  units:
    - name: update-sysctl.service
      command: start
      content: |
        [Unit]
        Description=Update sysctl values written by cloud-config
        [Service]
        ExecStart=/usr/lib/systemd/systemd-sysctl ...
DanArl
  • 2,511
  • 1
  • 10
  • 6
IanB
  • 261
  • 2
  • 9
2

Thanks for others for some tips.

You can do this to run arbitrary commands similar to runcmd.

- name: runcmd.service
  command: start
  content: |
    [Unit]
    Description=Runs a command

    [Service]
    Type=oneshot
    ExecStart=/bin/sh -c "touch /etc/environment;"
devnull
  • 49
  • 1
0

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
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • 2
    The CoreOS `cloud-init` has limited keys available, and `runcmd` or `bootcmd` are not in the list. – Andy Shinn Jun 11 '14 at 00:34
  • Figures they'd do something strange. You might have to force a reboot to get this applied. cloud-init doesn't seem to have any way to start or restart services directly. – Michael Hampton Jun 11 '14 at 00:39