0

我想知道为什么我的代码在使用 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
4

1 回答 1

1

它挂起是因为你做错了事。您不想在配置映像时运行OpenVAS 服务,而只想安装它。

该服务仅应在使用该映像的机器启动时运行。在这种情况下,您可能希望使用 systemd 来启动服务。我自己还没有安装这个包,但是我在网上查了一下,看起来它会自动为你安装必要的 systemd 配置,但最好通过创建你的图像实例并查看服务器是否是跑步。根据您上面的配置,我猜这些标志无论如何都是默认值,因此可能没有必要。如果它们不是并且你真的很喜欢它们,那么你可能会在某个地方放置一个配置文件,系统会在启动时注意到它,并且你的配置脚本无法使用它sed来将它们放入 systemd配置文件。

解决方案:在配置期间不要运行 OpenVAS。

于 2021-04-15T18:41:14.710 回答