[RESOLVED] Run custom script when creating, updating and deleting virtual servers?

13 posts / 0 new
Last post
#1 Mon, 10/10/2011 - 15:20

[RESOLVED] Run custom script when creating, updating and deleting virtual servers?


Any hooks in place to call external code on update/create/delete of virtual servers in virtualmin GPL? I'd like to be able to do other things when virtualmin changes servers.

As my first example, which I'm trying to do now:

I've got some code I'm working on to sync zone files of created/edited virtualmin domains to Rackspace's DNS servers via their cloud API. Works great on the commandline, but would like to not have to create a domain in virtualmin, then call my code with the same domain on the commandline to sync the domains to Rackspace DNS.



Sat, 10/15/2011 - 09:43

Am I posting in the wrong forum? Is there a better place to ask for a hook? Perhaps a feature request forum?




Fri, 05/23/2014 - 10:01 (Reply to #2)

mogmismo, were you able to put something in place to keep your Rackspace Cloud DNS synced with your server's DNS? I'm also looking to implement something like this and perhaps we could package it into a virtualmin module?

Sat, 10/15/2011 - 09:47


Sorry, I missed your post earlier... take a peek at System Settings -> Virtualmin Config -> Actions upon user and server creation -- and look at the various "Command to run before" options there, I think those are what you're after.


Mon, 02/06/2012 - 12:40 (Reply to #4)

Just what I was looking for. Thanks for your help andreycheck!

Thu, 01/12/2012 - 21:59

Hi All,

Could you please elaborate on how I could use this feature to automatize the following steps currently I do manually:

  1. I create a virtual server using Virtualmin, let's say 'example.com';
  2. I then run crontab -e command in ssh;
  3. In opened file I enter
*/15 * * * * /usr/bin/wget --no-check-certificate --quiet -O - http://example.com/cron.php

to run cronjob every 15 minuts. (If someone wonders - yes, all the websites I create have cron.php file)

Is it somehow possible in Virtualmin?

Tue, 12/20/2011 - 15:39


Thu, 12/22/2011 - 03:17

Could anyone address my question on https://www.virtualmin.com/node/19774#comment-92515, please?

Wed, 12/28/2011 - 13:12 (Reply to #8)

Assuming virtualmin uses the built-in /usr/sbin/useradd, you could create a shim file in its place. The shim file would run the standard grab the username from the parameters, add the user as normal, then create the user's cron file. I'm no BASH guru so I'll do it here in pseudo-code:

#  A shim file to add users and create their cron jobs
#  Place this in /root/bin/adduser-cron with at least 700 permissions
#  Other user/group perms may be necessary. 
# get username from parameters for later creation of cron file
while getopts ":pq:" optname
    case "$optname" in
        new_username == $optname
#add user as normal

/usr/sbin/useradd-stock $@
/bin/touch /var/spool/cron/$new_username
echo "*/15 * * * * /usr/bin/wget --no-check-certificate --quiet -O - http://example.com/cron.php" >> /var/spool/cron/$new_username


mv /usr/sbin/useradd /usr/sbin/useradd-stock
ln -s /root/bin/adduser-cron /usr/sbin/useradd

Be forewarned that if you update your OS and some package overwrites /usr/bin/useradd (shadow-utils for example) then you will loose your modified version and have to re-do the "mv ....ln -s" bit.

It may not be ideal, but it should work.


Fri, 12/30/2011 - 15:06 (Reply to #9)

Thank you ReachONE. I'll try this code after holidays.

Thu, 01/12/2012 - 12:20 (Reply to #10)

did it work?

Thu, 01/12/2012 - 22:03 (Reply to #11)

Hi ReachONE,

Because of your assumption "Assuming virtualmin uses the built-in /usr/sbin/useradd" and since it is a production server, I was so reluctant that I changed my mind. I will just do some manual work when creating accounts. It feels safer for me. But I will try this if I will have a chance to have testing environment.

Fri, 12/23/2011 - 14:45

another bump

Topic locked