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?
You can grant sudo rights to bamboo user by adding this to the instance startup script in you image configuration:
sudoersFile=/etc/sudoers.d/90-bamboo-sudo
echo "$ADMIN_USER ALL=(ALL) NOPASSWD:ALL" >$sudoersFile
chmod 0440 $sudoersFile
The problem is that your job will always fail. You can avoid that by putting shutdown into nohup / background, but then there's a chance that yuor agent will pick up another job and that job will fail.
Another approach would be to use ec2-terminate-instances in your script task.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For Windows, using ec2-terminate-instances is your best bet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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 from https://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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.