New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
After an OpenVZ VPS is created, can i automatically execute some vzctl commands on it?
After an OpenVZ VPS is created/mounted/started(vzctl start), can i set the host server so it automatically execute some vzctl commands on the VPS?
i mean enable tun/tap
set netfilter full for the virtual machine
append new line into /etc/vz/conf/CTID.conf
VPS is created from within web panel which i cant tweak so this would need to be set on the host server to execute by default on aall new VPS
Comments
/etc/vz/dists/scripts/postcreate.sh
Does the panel you're using not give you this functionality?
Thank you, in this file they says:
Runs on the host system and performs these postinstall tasks for a particular container (specified by $VE_ROOT environment)
i assume $VE_ROOT is for example "/vz/root/3050"
and to get CTID for further use (like for vzctl commands) i just add line:
VPSID=$(echo $VE_ROOT |grep -o '[0-9]*')
vzctl set $VPSID parametershere
Can't you also just add this stuff in the default vz.conf file?
How did you create your OpenVZ containers? Manually, WHMCS modules or script? Essentially you might need to attach some kind of hooks upon CT (re)created.
You can edit the default config at
/etc/vz/conf/*.conf-sample
and it gets copied to CT configuration during creation.Alexander
Into /etc/vz/dists/scripts/postcreate.sh i pasted function like:
customcommands()
{
VPSID=$(echo $VE_ROOT |grep -o '[0-9]*')
vzctl set $VPSID --ioprio 3 --save
}
and called it within that script. After i do vzctl create, it says that "Container already locked".
I see there is also /etc/vz/dists/scripts/prestart.sh file, but it is used also on VPS restarts.
@AlexanderM
$ cat /etc/vz/vz.conf|grep CONFIGFILE
CONFIGFILE="vswap-256m"
that config file is there: /etc/vz/conf/ve-vswap-256m.conf-sample
OpenVZ says: "During container creation, this configuration file is copied to CTID.conf, for example, with CTID of 123: /etc/vz/conf/123.conf"
so i assume i just need to edit that file ve-vswap-256m.conf-sample in my case or other *.conf-sample file if im using web based control panel to automate VPSs setups using different templates.
You need to wait until the container is fully setup before running commands, add something like sleep 10 to your script
@linuxthefish , that is good idea
i also wish to confirm that method with modiffying /etc/vz/conf/ve-vswap-256m.conf-sample file and other .conf-sample files worked to populate newly created VPSs conf files with additional values like in my case:
IOLIMIT="numberhere"
IOPSLIMIT="numberhere"