#cloud-config

users:
  # Allow logins via petri/petri for debugging.
  - name: petri
    passwd: "$6$EO8qjMcfYFra1zR8$ZHzeU29UoO49S3gJMivhgsP7farZgEbfOkKeXfswZeT7go1SpyPbL68whWCG5.YEdS4NeyPYYZYiLo5Fq4igV0"
    lock_passwd: false
    groups: users, admin

write_files:
- path: /etc/systemd/system/pipette.service
  content: |
    [Unit]
    Description=Petri pipette agent

    [Service]
    ExecStart=/cidata/pipette
    # Tracing goes over mesh, but log any local output to the console.
    StandardOutput=kmsg+console
    StandardError=kmsg+console
    # Kill the VM on failure, since we have no communication channel.
    FailureAction=poweroff-immediate

    [Install]
    WantedBy=cloud-init.target
- path: /etc/init.d/pipette-openrc
  content: |
    #!/sbin/openrc-run

    description="Petri pipette agent"
    command="/cidata/pipette"
  permissions: '0755'

bootcmd:
  # Mounts module is not configured in some (all?) distros, so mount /cidata manually.
  - [mkdir, -p, /cidata]
  - [mount, LABEL=cidata, /cidata, -o, ro]
  # Disable snapd, which takes a long time to start and is not needed.
  - systemctl disable snapd.service snapd.apparmor snapd.seeded.service || true
  - systemctl mask snapd.service || true

runcmd:
  # Add the service to systemd (most distros) or openrc (Alpine).
  - |
    if [ -x /usr/bin/systemctl ]; then
      systemctl enable pipette && systemctl start --no-block pipette
    else
      rc-update add pipette-openrc default && rc-service pipette-openrc start
    fi
