Build is stop when using loginctl in shell script provisioner

Hi Packer Community,

I’m working on packer to build custom AMI for AWS EC2 instances.

I use the shell provisioner to exec multiple scripts from the inline attribute like in the following example :

provisioner "shell" {
    # allow the server to disconnect from Packer without throwing an error. A disconnect might happen if you restart the SSH server or reboot the host
    expect_disconnect = true
    environment_vars = [
      "DEBIAN_FRONTEND=noninteractive"
    ]
    inline = [
      "sudo /tmp/script1.sh",
      "sudo /tmp/script2.sh"
    ]
  }

My first script end with a command loginctl terminate-user ubuntu, and packer stop the provisioning without executing script2.sh.

Do you have an idea to solve this ?

Thanks

To resolve the issue of Packer stopping the provisioning process after the loginctl terminate-user command, try appending an ampersand (&) survivor io mod apk download to the command in your shell script provisioner. This allows it to run in the background, allowing the remaining scripts to execute uninterrupted.