2 years ago
#52492

Eddysanoli
SSM Command never finishes executing. Any way to signal its end based on stdout?
I'm trying to start a minecraft server by sending some commands to an EC2 instance using the AWS-SDK for javascript.
ssm.sendCommand({
DocumentName: "AWS-RunShellScript",
InstanceIds: ["ec2-instance-id"],
TimeoutSeconds: 3600,
Parameters: {
commands: ['cd /home/ec2-user/minecraft/server', 'screen -S mc_server', 'java -Xmx3G -Xms3G -jar server-1-18.jar nogui']
}}, function(err, data) {
if (err) {
console.log("\nError:", err);
} else {
console.log("\nSuccess: ", data);
}
}
);
The command works correctly and I'm able to connect to the server after some waiting. The detail that bothers me is that the last command (java -Xmx3G -Xms3G -jar server-1-18.jar nogui
) never finishes executing because it continously logs the different server events until the server is stopped manually. However, when the server finishes loading it prints to the stdout something like:
Done! Finished in xxx seconds.
I would like to track the command stdout and signal the SSM executor to mark the command as finished, after that line is shown. I need to do this, because to stop the server properly, I need to re-attach the screen and then send the command /stop
, but because the previous command is still running, it returns an error.
My overall goal is to start the server with a script, and then be able to stop it properly. I know I could just stop the instance to stop the server, but this could lead to corrupted chunks in my world. Maybe there is a better way to do this. Any help is appreciated. Thanks!
javascript
amazon-web-services
aws-sdk-js
aws-ssm
0 Answers
Your Answer