I have a single-instance license, which I want to assign to a linux-32 job, then to a linux-64 job, with each job containing a 'final' task to shut down the instance, so that the other job can have a chance.
I tried creating a 'script' task with 'sudo shutdown -h now', but it didn't have any effect. Possibly the task doesn't have 'sudo' privileges I suppose?
What is best practice method, or what is any possible method, to shut down an instance from a task?
Edit, in response to answer below:
Ok, I'm trying to avoid having to create a custom image if possible, since it's often easier to just set everything up from a startup script when this is possible.
> You can avoid that by putting shutdown into nohup / background
Yes, this is my current strategy. In the startup script I put:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
cat <<END >flaggedshut.sh
while true; do {
echo "polling..."
if [[ -f /tmp/shutdown.flg ]]; then {
echo "shutdown now..."
shutdown -h now
} fi
sleep 3
} done
END
chmod +x flaggedshut.sh
nohup bash flaggedshut.sh > /tmp/nohupout.txt 2>&1 &
|
... then I create a task to create the /tmp/shutdown.flg file.
What about for Windows? If I've understood correctly fromhttps://answers.atlassian.com/questions/175456/instance-startup-script-vs-ec2-user-data-on-windows-elastic-agents , the startup script doesn't get executed on Windows boxes? And the tasks are run as a non-admin user, so not obvious how to install things / trigger shutdown on Windows?
> Another approach would be to use ec2-terminate-instances in your script task.
Ah, that sounds like it would answer this specific question, which means I probably need to make a new question to ask how to run a startup script, and install things, on Windows?