[英]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.