Account plans template question

SYSTEM INFORMATION
OS type and version Ubuntu 22
Virtualmin version Latest

Hi,

I am trying to create 4 website templates that I can use to deploy sites from. The templates are sets of files+database and when creating a new Virtual Server I need to be able to select what exact template to use so that those are deployed into public_html after the Virtual Server was created.

Can this be achieved with “Account plans”. Where can I find info how to set something like this up? Or should I used something else instead?

Please advise
Thanks

From what I can see you deploy them when you edit the virtual server, I can’t see that option in the account plan.

Or is it possible to perhaps run a custom script after the creation of a Virtual Server?

Please advise

Well check the command line doc for that.

For a collection of files that you want automatically copied into a new virtual server, Server Templates allow you to select a different skeleton directory per-template. So, start there. (That’s in Server Templates->Name of Template->Home Directory->Skeleton directory for files.)

You may then want to use Account Plans to choose a specific Server Template.

1 Like

Also, it sounds like maybe you’re mixing up Account Plans and Server Templates. Account Plans are about quotas and limits and features, mostly, and are quite simple, Server Templates are about configuration and can be quite complex…and can change just about everything about how Virtualmin creates domains. If you’re trying to, say, automatically setup specific applications and web configuration to suit those applications, that would be something you’d do in Server Templates (one way or another).

2 Likes

Thanks Joe, initially I used your suggestion but then I remembered that I can’t run MySQL related stuff with the skeleton directory. Instead I ended up setting up an action script via Virtualmin Configuration that would perform certain commands based on the plan ID the new Virtual Server is set to be in:

#!/bin/bash
# Script that is executed by virtualmin after a Virtual Server creation.
# It will deploy default website based on the plan ID assigned to the Virtual Server

# Assign variables
PLANID=${VIRTUALSERVER_PLAN}
DOMUID=${VIRTUALSERVER_USER}
DOMHOME=${VIRTUALSERVER_HOME}
DOMAIN=${VIRTUALSERVER_DOM}
DESCRIPTION=${VIRTUALSERVER_OWNER}
DB=${VIRTUALSERVER_DB}
DBUSER=${VIRTUALSERVER_MYSQL_USER}
DBPASS=${VIRTUALSERVER_MYSQL_PASS}


# Quit if public_html not empty
if [ -f "${DOMHOME}/public_html/index.php" ] || [ -d "${DOMHOME}/public_html/mfolder" ] || [ ! -d "${DOMHOME}/public_html" ]; then
                echo "Domain exists already or is being removed, quitting..." >> /tmp/script.log
                exit 1

fi

case "${PLANID}" in
        '157200348827732')
                echo "Deploying static site..." >> /tmp/script.log
                rsync -a /home/plans/static/public_html/ ${DOMHOME}/public_html/
                chown -R ${DOMUID}:${DOMUID} ${DOMHOME}/public_html
                sed -i "s/VIRTUALSERVER_OWNER/${DESCRIPTION}/g" ${DOMHOME}/public_html/index.html
                sed -i "s/VIRTUALSERVER_DOM/${DOMAIN}/g" ${DOMHOME}/public_html/index.html
                exit 0
                ;;
        *)
                echo "Undefined Plan ID, quitting..." >> /tmp/script.log
                ;;
esac



/usr/bin/printenv > /tmp/envs.txt

Hope this helps anyone who wants to setup something similar.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.