简体   繁体   English

我们可以通过 AWS SSM 作为后台进程运行命令吗?

[英]Can we run command as background process through AWS SSM?

I am trying to sync a S3 bucket which takes close to 3 hours to completely sync.我正在尝试同步一个 S3 存储桶,这需要将近 3 个小时才能完全同步。

sync-bucket.sh:同步bucket.sh:

nohup aws s3 sync "$source_bucket/$folder/" "s3://$destination_bucket/" \
        --profile abc --acl bucket-owner-full-control --sse "aws:kms" \
        --sse-kms-key-id "$KEY_ARN" > /var/log/$folder.log 2>&1 &

echo "Successfully triggered the sync job"

I was hoping to trigger the sync job using AWS SSM send command something like below:我希望使用 AWS SSM 发送命令触发同步作业,如下所示:

trigger.sh:触发器.sh:

COMMAND=$(aws ssm send-command --document-name "AWS-RunShellScript" \
            --targets "Key=instanceids,Values=${RECOVERY}"  \
            --parameters '{"executionTimeout":["10800"],"commands":["/opt/scripts/sync-bucket.sh"]}' \
            --output-s3-bucket-name "some-bucket" \
            --timeout-seconds 10800 \
            | jq -r '.Command.CommandId')

My observation is that SSM waits for this background job to finish before marking the execution as 'Success'.我的观察是 SSM 在将执行标记为“成功”之前等待此后台作业完成。 Is there a way we could perhaps just trigger the background job and make SSM finish the execution without having to wait for background job to finish?有没有办法我们可以只触发后台作业并使 SSM 完成执行而不必等待后台作业完成?

Or is there a better way of doing this?或者有没有更好的方法来做到这一点? I am basically trying to automate the process here and happy to let the job running in background on demand without having to login to instance and run command manually.我基本上是尝试在此处自动化该过程,并且很高兴让作业按需在后台运行,而无需登录到实例并手动运行命令。

Thanks for your time.谢谢你的时间。

The issue isn't that SSM is waiting for your background command to finish, it's that your command isn't actually put into background because your nohup command waits for input.问题不在于 SSM 正在等待您的后台命令完成,而是您的命令实际上并未放入后台,因为您的nohup命令等待输入。 To fix, replace nohup whatever_your_command_is & by nohup whatever_your_command_is < /dev/null 2> /dev/null > /dev/null &要修复,请用nohup whatever_your_command_is & nohup whatever_your_command_is < /dev/null 2> /dev/null > /dev/null &替换nohup whatever_your_command_is & nohup whatever_your_command_is < /dev/null 2> /dev/null > /dev/null &

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 AWS CodeDeploy 上为 django runserver 命令运行新的 shell 进程 - Run a new shell process for django runserver command on AWS CodeDeploy 如何在后台运行进程并在同一命令行中更改目录 - How to run a process in background and change directory in the same command-line 在新的后台运行命令 tmux window 并等待进程完成 - Run command in new background tmux window and wait for process to finish “如何使用 su -c 将单个命令作为后台进程运行 - "How to run a single command as a background process using su -c Python:在后台运行带有重定向的bash命令并获取进程ID - Python: Run bash command with redirection in background and get the process id 如何在后台运行此命令行? - How can I run this command line in the background? 如何通过C#进程运行export bash命令? - how to run export bash command through C# process? Shell脚本在后台使用ssh远程运行命令whit nohup,但是无法关闭此ssh进程。 但是我用的屏幕都完美 - shell script use ssh remote run command whit nohup in the background,but this ssh process can not be close. but I use the screen is all perfect 当进程通过脚本运行时,jobs 命令结果为空 - jobs command result is empty when process is run through script 向后台进程发送命令 - Send command to a background process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM