I am working on an app that connects all of my computers and servers I have access to, to my iOS devices, so that I can check on the status of services, I've named this app gRID, with the idea of everything connecting to my phone.

I do already use a system like this, called iStat, which allows you to see detailed information about your iOS device, Macs and servers you have access to. This also stores the information as a graph, making it very easy to see how your device was performing at any one time: 


The major downside to this app, which I have let the developers know about, is the lack of notifications. It would be amazing, if the app could let you know when the load gets over 50% of the graph, or your hard disk space went over 80%.

Having voiced these suggestions, I then decided to work on a crude version of this for myself. But at the same time, add in some additional functions. So far this is what I have:

  • Can be installed on Linux/Mac (as long as it has cURL)
  • Allows for the following commands:
    • Reboot machine
    • Test command ("say hello")
    • Reboot Apache
    • Reboot MySQL
    • Setup/Shutdown cam (this is for a Raspberry Pi security camera I have set up)
    • Update script

The way this system works is that on the various machines, a cron is run every 5 minutes (or on a Mac, a loaded launch daemon), this "checks in" to my phone, and asks for any commands. If there are any it runs each one in term (this can be an issue for reboot, as it runs this one first..note to self..)

Then, every hour, another cron runs and this "updates" the grid script, meaning I can add new commands in without having to log into every computer.

This is crucial for some servers as we have had clients update the password to the server and they've not let us know. To stop us have to call/email the client and wait a couple of days for them to reply, we can send remote commands (reboot apache) but then also add in new functionality, which will be up and running within 1 hour.

However, there are times I want to update this quicker. For example I want to quickly add in the functionality to give me a load balance for the server via email, to easily asses the load on the server. As 'time is of the essence' things like this are crucial to get fixed quickly.
And more often than not, I send an update out, which breaks on other machines (a linux only command, that I've put in the Mac version, or left the debugging level too high)

For these times, I would like to be able to tell the script "update yourself", or at least say "run the update script in 2 minutes".

Update yourself

The reason I cannot run the "update yourself" is because the file isn't stored in memory when it is run, it is loaded directly from the file. So, if I updated it to include an extra 5 lines, once the script had updated, instead of just carrying on, it would load the file back in, and continue from where it left off, which would now be 5 lines before where it should be, and in a dangerous position (reboot command ran without my consent, how dare it!)

Run update script in x minutes

So my ideal solution is the "run the update script in two minutes", but I cannot for the life of me find anything online that will allow me to do this! I can add a cron, that will run the command every two minutes, but that's not what I want it to do, and it'll mean removing it from the cron lists; which could cause issues if it takes more than 2 minutes to update.

So, if anyone has any ideas on how to run the script x minutes after the script currently open has run, I would be very grateful!