Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


After an OpenVZ VPS is created, can i automatically execute some vzctl commands on it?
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.

After an OpenVZ VPS is created, can i automatically execute some vzctl commands on it?

postcdpostcd Member
edited February 2016 in Help

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

    Thanked by 1postcd
  • Does the panel you're using not give you this functionality?

    @postcd said:
    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

  • postcdpostcd Member
    edited February 2016

    @rds100 said:
    /etc/vz/dists/scripts/postcreate.sh

    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.

  • AlexanderMAlexanderM Member, Top Host, Host Rep

    You can edit the default config at /etc/vz/conf/*.conf-sample and it gets copied to CT configuration during creation.

    Alexander

    Thanked by 1postcd
  • postcdpostcd Member
    edited February 2016

    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

  • postcdpostcd Member
    edited February 2016

    @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"

Sign In or Register to comment.