Linode Forum Index Linode Forum
Linode Community Forums
 


Automating rebuild

Click here to go to the original topic

 
       Linode Forum Index -> General Discussion
Author Message
mahemoff



Joined: 20 Jan 2012
Posts: 5

Posted: Fri Jan 20, 2012 7:34 am    Post subject: Automating rebuild  

Has anyone got something like this working, a bash script to delete an instance and bring it back up again using a StackScript?
Back to top  
obs



Joined: 07 Mar 2010
Posts: 1403
Location: Earth

Posted: Fri Jan 20, 2012 8:32 am    Post subject:  

Yes you'll want to look at the api http://www.linode.com/api/
Back to top  
mahemoff



Joined: 20 Jan 2012
Posts: 5

Posted: Fri Jan 20, 2012 8:48 am    Post subject:  

I should have said - I have been using the API, and I did get started building something, but it turns out to be a ton of work to replicate the dashboard's Rebuild and Reboot functionality.

You have to fire off a number of jobs, monitor their status, etc. So I was wondering if anyone had automated all that via the API.
Back to top  
obs



Joined: 07 Mar 2010
Posts: 1403
Location: Earth

Posted: Fri Jan 20, 2012 8:59 am    Post subject:  

You shouldn't have to monitor the status of any jobs since they all execute in order, all you need to do is queue them up in the right order.

A workflow like this should work
1) Shutdown the linode
2) Delete all the disks and config profiles
3) Deploy from your stack script
4) Create a swap partition
6) Create a new config profile with the disks from 3 and 4
7) Boot the profile from 6

You can have the stack script mail you when it's complete and issue a reboot to itself and let lassie bring it back up.

You can do all that in only a hand full of bash commands
Back to top  
mahemoff



Joined: 20 Jan 2012
Posts: 5

Posted: Fri Jan 20, 2012 9:18 am    Post subject:  

It's asynchronous though, unless someone's made a blocking API wrapper.

You generally have to fire these off, get their job ID, and poll until the job is complete before moving on to the next one. Not rocket science, but not trivial either.
Back to top  
obs



Joined: 07 Mar 2010
Posts: 1403
Location: Earth

Posted: Fri Jan 20, 2012 9:20 am    Post subject:  

No it's synchronous, the jobs are queued and performed one after the other. Send a bunch using the api and check the manager queue you'll only ever see one running.
Back to top  
mahemoff



Joined: 20 Jan 2012
Posts: 5

Posted: Fri Jan 20, 2012 9:42 am    Post subject:  

I see, thanks.

Still interested if anyone has a sample script, but if not, this makes it a lot more straightforward.
Back to top  
obs



Joined: 07 Mar 2010
Posts: 1403
Location: Earth

Posted: Fri Jan 20, 2012 9:44 am    Post subject:  

This is what I wrote to send commands to the api https://github.com/rwky/Linode-Bash-API it has some macros in there which can guide you on how to capture disk ids etc.
Back to top  
mahemoff



Joined: 20 Jan 2012
Posts: 5

Posted: Fri Jan 20, 2012 10:18 am    Post subject:  

Thanks, I've been using the Ruby wrapper, but this looks fine too.

I think the business about Job IDs still makes it a non-trivial exercise though, as a script needs to notify if things are failing.
Back to top  
 
       Linode Forum Index -> General Discussion
Page 1 of 1