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.
Am I posting in the wrong forum? Is there a better place to ask for a hook? Perhaps a feature request forum?
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.
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
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.
Thank you ReachONE. I’ll try this code after holidays.
Could you please elaborate on how I could use this feature to automatize the following steps currently I do manually:
- I create a virtual server using Virtualmin, let’s say ‘example.com’;
- I then run
crontab -e command in ssh;
- 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?
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.
Just what I was looking for. Thanks for your help andreycheck!
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?