Question: Script to run on delete of server

When a new server is created, there is an option to run a script at the end of the server creation process.

Is there one that can be run when a server is deleted?

When a server is created, I run a script that does some final installation stuff and then sends an XML document to a remote server to create an account.

When a server is deleted, I’d like to also automatically send an XML document to the remote server to delete the account?

Is this an option? If so, where do I set it up?

Well, in Module Config -> Actions upon user and server creation -> Command to run after making changes to a server, that’s triggered if a Virtual Server is created, modified, or deleted.

Is there a variable or other means for me to detemine (since it’s all the same script) whether the server was created, modified or deleted?

I handle it being run when ‘modified’ within my script by the existence of certain files within the server. However, if there was a variable or some other way for me to determine the action being taken, that would be great.

I’m assuming that Custom Fields are availabe to this script for any action, correct?

I guess the bigger question is: Has the server’s public_html directory been deleted already on a delete? That would be a pretty easy way to tell, but it’s not clear at what point this is run on a delete.

Those are all excellent questions.

And I’m sure there’s an answer to each one!

But I have no idea :wink:

Re-reading the docs, it looks like all those are environment variables.

So what I’d do from within your script is print out what environment variables are available to you when your script is called.

As far as if public_html has been deleted or not – I suspect that’s the distinction between these two options:

  1. Command to run before making changes to a server

  2. Command to run after making changes to a server

I imagine if you use #1, than public_html would still be there. If you use #2, it would have been deleted first.

Thanks Eric, got it.

Yes, public_html is in fact already deleted so it’s easy to check for that case. That tells me I’m in a “delete virtual server”.

If certain files don’t exist in public_html then I know that it is a ‘create server’ situation.

Other than that, it is a modification.

Would certainly be cleaner (and make smaller, less buggy scripts) to be able to define a different script for each of the cases. But this will work right now for me.

An additional improvement would be to enable output of the scripts going to the screen when the operation is performed.