Alow running custom bash/php/another scripts per template

As mentioned on https://www.virtualmin.com/node/19774 there is an option to run scripts when creating virtual servers, however this option is set in Virtualmin configurations and thus is for ALL virtual servers. I suggest to introduce such an option to run custom php/bash/perl/another scripts per template.

For example, we don't need to run our custom script for phpMyAdmin, but need to do so for every Drupal website newly deployed on the system. Currently we run it manually on command line, it would be very nice to be able to trigger it through a custom template we use when creating a new Drupal website.

And our custom scrip is not an installation script, so doesn't relate to https://www.virtualmin.com/documentation/developer/scripts Introducing such small feature would enable Virtualmin users to do lot's of things during creation of virtual servers.

Thanks for consideration!

Status: 
Closed (fixed)

Comments

Howdy,

Virtualmin actually passes all the variables found in the various files within "/etc/webmin/virtual-server/domains/" to the script that's run when creating a new domain.

So one example of what you could do is look at the value of "template" environment variable.

If you run the command virtualmin list-templates, you can see all the possible values for the template variable.

Using that, you could test on that variable from within the script and then perform certain actions only when a specific template is being used (or other criteria).

Would that do what you're after?

Thanks for the suggestion, but it seems to be too complex to run simple script after creation of a virtual server. Another problem that "Command to run after making changes to a server" option runs a script on EVERY change on a virtual server and we need to run our script just once after creating a VS. Would be really nice to trigger a custom template to run a custom script (not installation script).

By the way we could put our custom script into /usr/libexec/webmin/virtual-server/scripts/ and treat it as installation script (though it is not), however it is written in bash and installation script seems must to be a perl script and have certain format. We are trying just to trigger a small bash script on VS creation here...

Talking about post server creation script, copying my suggestion from a relevant discussion on http://virtualmin.com/node/33498#comment-133669

The "post-domain creation" feature appears to be triggered on every single edit as the wording suggests:

Command to run before making changes to a server
Command to run after making changes to a server

and doing so could break the existing websites. So it would be much more stable and under control if the above would be changed or additionally added as:

Command to run before creating a serverĀ 
Command to run after creating a server

and trigger this only ONCE just before or after server creation and never again.

But even if this was implemented then it would be really nice to delegate this to the templates as there could be lot's of cases when users won't want to run post creation scripts on certain situations when, for example, creating phpMyAdmin or webmail UIs. At the same time they would want to run post VS creation scripts only on certain templates.

I do believe delegating post VS creating scripts to templates would make Virtualmin much flexible and useful to custom situations.

The post-change script can actually detect if it is being run for a domain creation, deletion, etc - and the details of which domain was created. The environment variable $VIRTUALSERVER_ACTION will be set to CREATE_DOMAIN this case, as documented on http://www.virtualmin.com/documentation/developer/prepost

If you want to do something only for a specific template, you can check $VIRTUALSERVER_TEMPLATE for the numeric ID of the template that the domain being created has assigned.

This actually takes care of my PER TEMPLATE and ONLY AFTER CREATION request, so marking this as closed.

Thanks you and sorry for not properly searching and not reading through http://www.virtualmin.com/documentation/developer/prepost

By the way, is there any recommended place to store such custom scripts or anywhere will do? Will variables work is script stored anywhere on the server?

Typically I store the scripts in the /etc/ directory, but anywhere is fine. The variables will work regardless of where the script is.