Packer 在我最后一个命令结束时挂起
Packer hangs at the end of my last command
我想知道为什么我的代码在使用 OpenVAS Scanner 构建结束时挂起。这是最后显示的内容:
==> Ubuntu AMI Builder: Provisioning with shell script: ../../pipeline/build/start.sh
Ubuntu AMI Builder: Creating Data folder...
Ubuntu AMI Builder: Running first start configuration...
Ubuntu AMI Builder: Creating Openvas NVT sync user...
Ubuntu AMI Builder: Wait for redis socket to be created...
Ubuntu AMI Builder: Testing redis status...
Ubuntu AMI Builder: Redis ready.
Ubuntu AMI Builder: Creating NVT Plugins folder...
Ubuntu AMI Builder: Fixing NVT Plugins folder...
Ubuntu AMI Builder: Updating NVTs...
Ubuntu AMI Builder: Removing leftover pid files from system
Ubuntu AMI Builder: Starting Open Scanner Protocol daemon for OpenVAS...
Ubuntu AMI Builder: Read and write capabilities for OpenVAS...
Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: + Your OpenVAS Scanner image is now ready to use! +
Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++
Ubuntu AMI Builder:
Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: +++++++++ Tailing Logs +++++++++
Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: OSPD[22021] 2021-04-15 03:44:05,252: INFO: (ospd.main) Starting OSPd OpenVAS version 20.8.1.
它成功了,但挂在我的脚本末尾,这让我很困惑。我的最后一段脚本如下:
####### Initiate ospd daemon for OpenVAS ########
echo "Starting Open Scanner Protocol daemon for OpenVAS..."
ospd-openvas --log-file /usr/local/var/log/gvm/ospd-openvas.log --unix-socket /data/ospd.sock --log-level INFO
while [ ! -S /data/ospd.sock ]; do
sleep 1
done
echo "Read and write capabilities for OpenVAS..."
chmod 666 /data/ospd.sock
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ Your OpenVAS Scanner image is now ready to use! +"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
echo "++++++++++++++++++++++++++++++++"
echo "+++++++++ Tailing Logs +++++++++"
echo "++++++++++++++++++++++++++++++++"
tail /usr/local/var/log/gvm/*
有谁知道为什么它在完成后挂在最后。如果可能的话,我将不胜感激!
更新:
我在供应商末尾没有 -F
的情况下更新了代码,它仍然继续挂起。我不确定 ospd-openvas
是否是罪魁祸首,但如果它不应用代码,它应该以循环结束。
更新更新:
这是我正在使用的供应商模板:
"provisioners": [
{
"type": "shell",
"execute_command": "sudo -u root /bin/bash -c '{{.Path}}'",
"scripts": [
"../../pipeline/build/build_ami.sh",
"../../pipeline/build/start.sh"
]
}
]
}
这里是我挂起后的调试日志:
2021/04/15 13:12:40 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2021/04/15 13:12:40 packer-builder-amazon-ebs plugin: [DEBUG] Opening new ssh session
2021/04/15 13:12:40 packer-builder-amazon-ebs plugin: [DEBUG] starting remote command: sudo -u root /bin/bash -c '/tmp/script_2838.sh'
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Creating Data folder...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Running first start configuration...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Creating Openvas NVT sync user...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Wait for redis socket to be created...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Testing redis status...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Redis ready.[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Creating NVT Plugins folder...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Fixing NVT Plugins folder...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Removing leftover pid files from system[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Starting Open Scanner Protocol daemon for OpenVAS...[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: Read and write capabilities for OpenVAS...[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: + Your OpenVAS Scanner image is now ready to use! +[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder:[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++ Tailing Logs +++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: OSPD[22185] 2021-04-15 18:12:41,530: INFO: (ospd.main) Starting OSPd OpenVAS version 20.8.1.[0m
2021/04/15 13:26:44 ui error: Cancelling build after receiving interrupt
2021/04/15 13:26:44 packer-provisioner-file plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-provisioner-file plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-provisioner-shell plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 Cancelling builder after context cancellation context canceled
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Cancelling provisioning due to context cancellation: context canceled
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Cancelling hook after context cancellation context canceled
2021/04/15 13:26:44 Cancelling provisioner after context cancellation context canceled
2021/04/15 13:26:44 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepSetGeneratedData'. Press enter to continue.[0m
2021/04/15 13:26:44 packer-provisioner-shell plugin: Retryable error: context canceled
2021/04/15 13:26:44 [INFO] (telemetry) ending shell
2021/04/15 13:26:50 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepConnect'. Press enter to continue.[0m
2021/04/15 13:26:51 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepCreateSSMTunnel'. Press enter to continue.[0m
2021/04/15 13:26:52 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepGetPassword'. Press enter to continue.[0m
2021/04/15 13:26:53 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue.[0m
2021/04/15 13:26:54 ui: [1;32m==> Ubuntu AMI Builder: Terminating the source AWS instance...[0m
2021/04/15 13:26:55 packer-builder-amazon-ebs plugin: [INFO] RPC endpoint: Communicator ended with: 0
2021/04/15 13:26:55 [INFO] 716 bytes written for 'stdout'
2021/04/15 13:26:55 [INFO] 0 bytes written for 'stderr'
2021/04/15 13:26:55 [INFO] RPC client: Communicator ended with: 0
2021/04/15 13:26:55 [INFO] RPC endpoint: Communicator ended with: 0
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] 716 bytes written for 'stdout'
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stderr'
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
它挂起是因为你做错了事。您不想在配置图像时 运行 OpenVAS 服务,您只想 安装 它。
只有在使用图像的机器启动时,服务才应该 运行。在这种情况下,您可能希望使用 systemd 来启动该服务。我自己还没有安装这个包,但我在网上查了一下,看起来它会自动为你安装必要的 systemd 配置,但最好通过创建你的图像实例并查看服务器是否是运行宁。根据您上面的配置,我猜想这些标志无论如何都是默认设置,因此可能没有必要。如果它们不是并且您真的依附于它们,那么您可能可以在某个地方放置一个系统在启动时会注意到的配置文件,如果失败,您的配置脚本可以使用 sed
来将它们放在 systemd 配置文件中。
解决方案:在配置期间不要运行 OpenVAS。
我想知道为什么我的代码在使用 OpenVAS Scanner 构建结束时挂起。这是最后显示的内容:
==> Ubuntu AMI Builder: Provisioning with shell script: ../../pipeline/build/start.sh
Ubuntu AMI Builder: Creating Data folder...
Ubuntu AMI Builder: Running first start configuration...
Ubuntu AMI Builder: Creating Openvas NVT sync user...
Ubuntu AMI Builder: Wait for redis socket to be created...
Ubuntu AMI Builder: Testing redis status...
Ubuntu AMI Builder: Redis ready.
Ubuntu AMI Builder: Creating NVT Plugins folder...
Ubuntu AMI Builder: Fixing NVT Plugins folder...
Ubuntu AMI Builder: Updating NVTs...
Ubuntu AMI Builder: Removing leftover pid files from system
Ubuntu AMI Builder: Starting Open Scanner Protocol daemon for OpenVAS...
Ubuntu AMI Builder: Read and write capabilities for OpenVAS...
Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: + Your OpenVAS Scanner image is now ready to use! +
Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++
Ubuntu AMI Builder:
Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: +++++++++ Tailing Logs +++++++++
Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++
Ubuntu AMI Builder: OSPD[22021] 2021-04-15 03:44:05,252: INFO: (ospd.main) Starting OSPd OpenVAS version 20.8.1.
它成功了,但挂在我的脚本末尾,这让我很困惑。我的最后一段脚本如下:
####### Initiate ospd daemon for OpenVAS ########
echo "Starting Open Scanner Protocol daemon for OpenVAS..."
ospd-openvas --log-file /usr/local/var/log/gvm/ospd-openvas.log --unix-socket /data/ospd.sock --log-level INFO
while [ ! -S /data/ospd.sock ]; do
sleep 1
done
echo "Read and write capabilities for OpenVAS..."
chmod 666 /data/ospd.sock
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ Your OpenVAS Scanner image is now ready to use! +"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
echo "++++++++++++++++++++++++++++++++"
echo "+++++++++ Tailing Logs +++++++++"
echo "++++++++++++++++++++++++++++++++"
tail /usr/local/var/log/gvm/*
有谁知道为什么它在完成后挂在最后。如果可能的话,我将不胜感激!
更新:
我在供应商末尾没有 -F
的情况下更新了代码,它仍然继续挂起。我不确定 ospd-openvas
是否是罪魁祸首,但如果它不应用代码,它应该以循环结束。
更新更新: 这是我正在使用的供应商模板:
"provisioners": [
{
"type": "shell",
"execute_command": "sudo -u root /bin/bash -c '{{.Path}}'",
"scripts": [
"../../pipeline/build/build_ami.sh",
"../../pipeline/build/start.sh"
]
}
]
}
这里是我挂起后的调试日志:
2021/04/15 13:12:40 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2021/04/15 13:12:40 packer-builder-amazon-ebs plugin: [DEBUG] Opening new ssh session
2021/04/15 13:12:40 packer-builder-amazon-ebs plugin: [DEBUG] starting remote command: sudo -u root /bin/bash -c '/tmp/script_2838.sh'
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Creating Data folder...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Running first start configuration...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Creating Openvas NVT sync user...[0m
2021/04/15 13:12:40 ui: [0;32m Ubuntu AMI Builder: Wait for redis socket to be created...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Testing redis status...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Redis ready.[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Creating NVT Plugins folder...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Fixing NVT Plugins folder...[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Removing leftover pid files from system[0m
2021/04/15 13:12:41 ui: [0;32m Ubuntu AMI Builder: Starting Open Scanner Protocol daemon for OpenVAS...[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: Read and write capabilities for OpenVAS...[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: + Your OpenVAS Scanner image is now ready to use! +[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++++++++++++++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder:[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: +++++++++ Tailing Logs +++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: ++++++++++++++++++++++++++++++++[0m
2021/04/15 13:12:42 ui: [0;32m Ubuntu AMI Builder: OSPD[22185] 2021-04-15 18:12:41,530: INFO: (ospd.main) Starting OSPd OpenVAS version 20.8.1.[0m
2021/04/15 13:26:44 ui error: Cancelling build after receiving interrupt
2021/04/15 13:26:44 packer-provisioner-file plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-provisioner-file plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-provisioner-shell plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Received interrupt signal (count: 1). Ignoring.
2021/04/15 13:26:44 Cancelling builder after context cancellation context canceled
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Cancelling provisioning due to context cancellation: context canceled
2021/04/15 13:26:44 packer-builder-amazon-ebs plugin: Cancelling hook after context cancellation context canceled
2021/04/15 13:26:44 Cancelling provisioner after context cancellation context canceled
2021/04/15 13:26:44 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepSetGeneratedData'. Press enter to continue.[0m
2021/04/15 13:26:44 packer-provisioner-shell plugin: Retryable error: context canceled
2021/04/15 13:26:44 [INFO] (telemetry) ending shell
2021/04/15 13:26:50 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepConnect'. Press enter to continue.[0m
2021/04/15 13:26:51 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepCreateSSMTunnel'. Press enter to continue.[0m
2021/04/15 13:26:52 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepGetPassword'. Press enter to continue.[0m
2021/04/15 13:26:53 ui: ask: [1;32m==> Ubuntu AMI Builder: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue.[0m
2021/04/15 13:26:54 ui: [1;32m==> Ubuntu AMI Builder: Terminating the source AWS instance...[0m
2021/04/15 13:26:55 packer-builder-amazon-ebs plugin: [INFO] RPC endpoint: Communicator ended with: 0
2021/04/15 13:26:55 [INFO] 716 bytes written for 'stdout'
2021/04/15 13:26:55 [INFO] 0 bytes written for 'stderr'
2021/04/15 13:26:55 [INFO] RPC client: Communicator ended with: 0
2021/04/15 13:26:55 [INFO] RPC endpoint: Communicator ended with: 0
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] 716 bytes written for 'stdout'
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stderr'
2021/04/15 13:26:55 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
它挂起是因为你做错了事。您不想在配置图像时 运行 OpenVAS 服务,您只想 安装 它。
只有在使用图像的机器启动时,服务才应该 运行。在这种情况下,您可能希望使用 systemd 来启动该服务。我自己还没有安装这个包,但我在网上查了一下,看起来它会自动为你安装必要的 systemd 配置,但最好通过创建你的图像实例并查看服务器是否是运行宁。根据您上面的配置,我猜想这些标志无论如何都是默认设置,因此可能没有必要。如果它们不是并且您真的依附于它们,那么您可能可以在某个地方放置一个系统在启动时会注意到的配置文件,如果失败,您的配置脚本可以使用 sed
来将它们放在 systemd 配置文件中。
解决方案:在配置期间不要运行 OpenVAS。