VSwap memory configuration on ISPConfig3 VServer container

jesse's picture

ISPConfig3 VServer containers only support UBC memory configuration right now (2015), this article implements a workaround using a vzctl action script to support VSwap instead.

vps.premount

The more I work with ISPConfig's VServer, the more I find workarounds needed in the config that is generated. This article utilizes a /etc/vz/conf/vps.premount script that builds on one used in this article about setting up vzfirewall with ISPConfig.

More specifically, this script will convert the container config files using the commands in Openvz VSwap aritcle, and then append an "addon" file to the end (either container specific or a default).

mkdir /etc/vz/conf/addon
 
cat > /etc/vz/conf/vps.premount <<'EOF'
#!/bin/bash
#
# vps.premount
#
 
#  Sanity check the environment
[ -z "${VEID}" ] && exit 1
[ -z "${VE_CONFFILE}" ] && exit 1
 
#  Source VPS configuration files in the same order as vzctl
[ -f /etc/vz/vz.conf ] || exit 1
[ -f ${VE_CONFFILE} ] || exit 1
. /etc/vz/vz.conf
. ${VE_CONFFILE}
 
if [ -d /etc/vz/conf/addon ]; then
  cd /etc/vz/conf/addon
 
  # NETFILTER= in .netfilter
  if ! grep -q ^NETFILTER= ${VE_CONFFILE}; then
    if [ -f ${VEID}.netfilter ]; then
      cat ${VEID}.netfilter >> ${VE_CONFFILE}
    elif [ -f default.netfilter ]; then
      cat default.netfilter >> ${VE_CONFFILE}
    fi
  fi
 
  # #FIREWALL= in .firewall
  if ! grep -q ^\#FIREWALL= ${VE_CONFFILE}; then
    if [ -f ${VEID}.firewall ]; then
      cat ${VEID}.firewall >> ${VE_CONFFILE}
    elif [ -f default.firewall ]; then
      cat default.firewall >> ${VE_CONFFILE}
    fi
  fi
 
  # vSwap in .vswap
  if ! vzlist -o vswap ${VEID} | grep -q yes; then
    # see http://openvz.org/VSwap#Convert_non-VSwap_CT_to_VSwap
    cp ${VE_CONFFILE} ${VE_CONFFILE}.pre-vswap
    grep -Ev '^(KMEMSIZE|LOCKEDPAGES|PRIVVMPAGES|SHMPAGES|NUMPROC|PHYSPAGES|VMGUARPAGES|OOMGUARPAGES|NUMTCPSOCK|NUMFLOCK|NUMPTY|NUMSIGINFO|TCPSNDBUF|TCPRCVBUF|OTHERSOCKBUF|DGRAMRCVBUF|NUMOTHERSOCK|DCACHESIZE|NUMFILE|AVNUMPROC|NUMIPTENT|ORIGIN_SAMPLE|SWAPPAGES)=' > ${VE_CONFFILE} <  ${VE_CONFFILE}.pre-vswap
 
    if [ -f ${VEID}.vswap ]; then
      cat ${VEID}.vswap >> ${VE_CONFFILE}
    elif [ -f default.vswap ]; then
      cat default.vswap >> ${VE_CONFFILE}
    else
      egrep '^PHYSPAGES|^SWAPPAGES' ${VE_CONFFILE}.pre-vswap >> ${VE_CONFFILE}
    fi
  fi
fi
 
if type -p vzfirewall > /dev/null; then
  #  Test vzfirewall config for errors before running
  if vzfirewall -t > /dev/null 2>&1; then
    vzfirewall -a > /dev/null 2>&1
  fi
fi
 
exit 0
EOF

Then create .vswap files with PHYSPAGES and SWAPPAGES values. Eg. to set container 105 to use 1G ram and swap, and default all others to 512M ram and swap:

cat > /etc/vz/conf/addon/105.vswap <<'EOF'
 
PHYSPAGES="0:262144"
SWAPPAGES="0:262144"
EOF
 
cat > /etc/vz/conf/addon/default.vswap <<'EOF'
 
PHYSPAGES="0:131072"
SWAPPAGES="0:131072"
EOF

This script cannot check for errors at runtime, as it runs after the container memory parameters have been read by vzctl. An implication of that is you must restart the container twice for the VSwap memory changes to be effective (the first time the changes are made to the config file, the second time the container restarts using those changes).

If the container doesn't start right, just copy back the .pre-vswap file and rename the vps.premount, then manually troubleshoot/fix.

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.