Amazon ec2 为什么我的SystemD服务在重新启动时不重新启动?

Amazon ec2 为什么我的SystemD服务在重新启动时不重新启动?,amazon-ec2,systemd,amazon-ami,hashicorp-packer,Amazon Ec2,Systemd,Amazon Ami,Hashicorp Packer,我正在使用Packer构建一个AMI,它配置了一个定制的SystemD单元。然后将AMI部署到EC2。问题是,如果EC2重新启动,则机组不会重新启动 这是我的单位: [Unit] Description=My service After=network.target StartLimitIntervalSec=0 StartLimitAction=reboot [Service] Type=simple Restart=always RestartSec=30 User=ubuntu Exec

我正在使用Packer构建一个AMI,它配置了一个定制的SystemD单元。然后将AMI部署到EC2。问题是,如果EC2重新启动,则机组不会重新启动

这是我的单位:

[Unit]
Description=My service
After=network.target
StartLimitIntervalSec=0
StartLimitAction=reboot

[Service]
Type=simple
Restart=always
RestartSec=30
User=ubuntu
ExecStart=/opt/app/app

[Install]
WantedBy=multi-user.target
这是我的打包机配置:

{
  "variables": {
    "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
    "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
    "region":         "{{env `AWS_REGION`}}"
  },
  "builders": [
    {
      "access_key": "{{user `aws_access_key`}}",
      "ami_name": "my-app-{{timestamp}}",
      "instance_type": "t2.micro",
      "region": "{{user `region`}}",
      "secret_key": "{{user `aws_secret_key`}}",
      "source_ami_filter": {
        "filters": {
        "virtualization-type": "hvm",
        "name": "ubuntu/images/*ubuntu-bionic-18.04-amd64-server-*",
        "root-device-type": "ebs"
        },
        "owners": [ "099720109477" ],
        "most_recent": true
      },
      "ssh_username": "ubuntu",
      "type": "amazon-ebs"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "script": "{{template_dir}}/provision.sh"
    },
    {
      "type": "file",
      "source": "{{template_dir}}/files/app.service",
      "destination": "/tmp/upload/etc/systemd/system/app.service"
    },
    {
      "type": "file",
      "source": "{{template_dir}}/../bin/Release/netcoreapp3.1/",
      "destination": "/tmp/upload/opt/app"
    },
    {
      "type": "shell",
      "inline": [
        "sudo rsync -a /tmp/upload/ /",
        "cd /opt/app",
        "sudo systemctl daemon-reload",
        "sudo systemctl enable app.service"
      ]
    }
  ]
}
奇怪的是,如果我SSH到正在运行的EC2中并启用该服务,那么它会在重新启动后重新启动

sudo systemctl enable app.service
sudo reboot
这让我觉得我没有正确创建AMI,但在我的打包机配置中,我确实启用了该服务

为什么我的AMI没有启用SystemD设备?