How to create deployment images used in virtualized environments
Overview
You can quickly deploy WP Squared on Virtual Private Servers (VPS) or Virtual Machines (VM) using images created from a template system. Follow these simple steps to build and prepare an image, using the snapshot_prep script, so that every instance will be ready for use without manual setup.
Never use on an active server with real customer data.
Prepare your system for templating
Prepare for templating by ensuring the following system requirements:
- Use 64-bit only: WP Squared works only on 64-bit systems.
- Disk size: Start with a virtual disk size of at least 20 GB. You can expand this later after deployment.
Pre-configure essential files (optional)
Before you run the snapshot_prep script, configure the following files:
| File | Description |
|---|---|
/etc/cpupdate.conf | Sets update preferences and release tier configurations. |
/etc/cpsources.conf | Configures update sources, particularly useful for WP Squared Partners using custom FastUpdate servers. |
This pre-configuration eliminates the need to manually log into each VM to configure basic settings before customer access.
Security and system updates
Before installing WP Squared, perform the following tasks:
- Update everything: Apply the latest OS and security patches.
- Clean up: Remove temporary files, logs, unique identifiers (like SSH keys and hostnames).
- Standardize: Make sure there’s nothing system-unique that could cause problems when you clone or start new VMs.
Install WP Squared
After you finish preconfiguring your installation, you can install WP Squared. For more information, read our installation documentation.
Run the snapshot_prep script
The snapshot_prep script prepares WP Squared and the services that it manages directly, such as MYSQL. You must prepare basic operating system and third-party services after you run the snapshot_prep script, for example, by regenerating unique server keys for SSH and license keys.
You can use the snapshot_prep script to prepare WP Squared servers for creating deployment images used in virtualized environments such as VPS or VM templates. The script cleans up server configurations and removes elements that could cause issues when cloning or deploying the image to new servers.
Not all server configurations support the snapshot_prep script. The script automatically detects and exits early when it encounters unsupported server configurations:
- Existing API tokens
- Existing backups or backup directories
- Two-factor authentication enabled for root
- Links to external servers via cluster or node configurations
- Configured contacts in
/etc/wwwacct.confor/etc/wwwacct.conf.shadow - Remote MySQL profiles configured in WHM’s Manage Database Profiles
This list does not represent all possible unsupported scenarios. The script may detect additional incompatible configurations.
Basic usage
You can run the snapshot_prep script from the command line with various options to control its behavior.
The basic command syntax:
/usr/local/cpanel/scripts/snapshot_prep
Options
The snapshot_prep script provides the following options to customize its behavior:
| Option | Description | Example |
|---|---|---|
--no-post-service | Do not install the on-first-boot service, requiring manual execution of post_snapshot after deployment. | --no-post-service |
--list-tasks | Display all tasks the script will perform without executing them. | --list-tasks |
--skip | Skip specific tasks during execution. Use a comma-delimited list of tasks to skip. Note:
| --skip=mysql,licenseNote: In this example, mysql and license represent the tasks you want to skip. |
--only | Execute only specified tasks. Use a comma-delimited list of tasks to run. Note:
| --only=licenseNote: In this example, license represents the tasks you wish to execute. |
--instance-packages | Specify packages to install during first boot for per-instance setup. Use a comma-delimited list of packages. | --instance-packages=package1,package2Note: In this example, package1 and package2 represent the packages you wish to install. |
--delete-saved-copies | Remove backup copies of configuration files created by the script. | --delete-saved-copies |
--help | Display help documentation and available options. | --help |
For plugin developers – add custom tasks (optional)
WP Squared does not create third-party plugins for the snapshot_prep script.
If you maintain third-party software for WP Squared servers, you can provide a plugin for your users to run with the snapshot_prep script. By using your plugin, users can run additional tasks when preparing their servers to create deployment images. For example, imagine your software includes a unique access token. You want each instance created from an image to have its own unique token. In this case, we recommend creating a third-party plugin that adds a task to perform the following:
Clean the token when a user runs the
snapshot_prepscript so that the token is not included in the image.Generate a new token upon the first boot of instances created from the image.
For a description of these tasks, as well as all other tasks in this script, use the --list-tasks option.
The snapshot_prep script uses .json files to point to a third-party plugin script. Before a plugin can run, your software must install a .json file in the /var/cpanel/snapshot_prep.d directory on your user’s server.
The .json file must use the following format:
1{
2 "name": "exampleplugin",
3 "type": "non-repair only",
4 "pre": ["/var/cpanel/exampleplugin.py", "--before"],
5 "post": ["/var/cpanel/exampleplugin.py", "--after"],
6 "description": "Perform a task.\n"
7}The .json file includes the following keys:
| Item | Description |
|---|---|
name | The name of the file, excluding the .json suffix. For example, if the file is named example.json, write example in the name field.Note: The file name can only include letters, numbers, and underscores. |
type | The type must be non-repair only. |
pre | An executable file and any additional arguments. |
post | An executable file and any additional arguments. |
description | A description of what the plugin does. |
deps | A list of one or more tasks. For more information, read about dependencies for third-party plugins. |
Dependencies for third-party plugins
This system allows third-party plugins to customize or replace the default dependencies as needed.
Third-party plugins in this system can define their own dependencies using the deps key in the plugin’s .json file.
By default, if no dependencies are specified, the following tasks are used as the default dependencies for all third-party plugins:
ipaddr_and_hostnamemysqlcpwhm_misc
However, these defaults can be overridden by specifying a deps key in the plugin’s .json file. The deps key should contain a list of one or more tasks that must run before this plugin. For example:
1{
2 "name": "exampleplugin",
3 "type": "non-repair only",
4 "pre": ["/var/cpanel/exampleplugin.py", "--before"],
5 "post": ["/var/cpanel/exampleplugin.py", "--after"],
6 "description": "Perform a task.\n",
7 "deps": ["wp_toolkit"],
8 "before": ["wp2"]
9}- Any tasks listed in
depsmust exist; otherwise, thesnapshot_prepscript will fail. - The optional
beforekey allows you to specify tasks that this plugin should run before (i.e., “this plugin must run before wp2”). If any tasks inbeforedo not exist, thesnapshot_prepscript will emit a warning, but it is not fatal. - Care must be taken when defining the
depsandbeforekey tasks, as circular dependencies will cause thesnapshot_prepscript to fail.
After running the script
Once completed, the script destroys some configuration and user data. Make sure there are no failed tasks. A success message will appear: System is ready for snapshotting.
If you need to remove the saved config file copies before imaging, run the following command:
/usr/local/cpanel/scripts/snapshot_prep --delete-saved-copies
If successful, the system will display the following success message: Deleted saved copies of configuration files.
Final template configuration
Your templates must meet or exceed our system requirements. Most providers offer a few different templates.
Deployment
Always double-check that your deployment image doesn’t contain unique or sensitive data from the template build process.
When deploying a new VPS/VM from your image, the system runs the post_snapshot script automatically to finish configuring the instance. If you used the --no-post-service option, run /usr/local/cpanel/scripts/post_snapshot script manually after the first boot. Consider using tools like libguestfs or virt-sysprep (--firstboot option) or your hypervisor’s similar features to run any further setup scripts. However, be cautious not to accidentally remove user accounts or cron jobs.
- To avoid locking your development licenses, create templates on unlicensed IP addresses if possible.
- Each new VM deployed should go through its own initial setup to prevent conflicts and ensure secure, isolated operation.