[SOLVED] Parallel startup for LXC Containers possible?

Aug 28, 2017
66
12
48
44
Hi there,

having >200 LXC Containers on a Server takes some time to bring all up on a Node Reboot, especially when they are started in a serial manner.
Is there a possibility to work with parallel starts to bring up the containers faster?
 
you could write it yourself, either with a script that gets called by a systemd unit, or with a systemd template unit and target. the current onboot start code is not that easy to make parallel, as we have to take configured ordering and startup delays into account. if you don't need any of that, you can simply not set onboot and start them on boot yourself ;) see the pve-guests.service unit for ordering (or simply order your unit after it).
 
We implemented it like this (the pve-guests still takes care of all containers as well, but we dont mind ;) )

Systemd File:
Bash:
# /etc/systemd/system/startupbooster.service
[Unit]
Description=PVE startup booster
ConditionPathExists=/usr/sbin/pct
RefuseManualStart=true
RefuseManualStop=true
Wants=pvestatd.service
Wants=pveproxy.service
Wants=spiceproxy.service
Wants=pve-firewall.service
Wants=lxc.service
After=pveproxy.service
After=pvestatd.service
After=spiceproxy.service
After=pve-firewall.service
After=lxc.service
After=pve-ha-crm.service pve-ha-lrm.service

[Service]
ExecStartPre=-/usr/share/pve-manager/helpers/pve-startall-delay
ExecStart=/usr/local/bin/startupbooster
Type=oneshot
RemainAfterExit=yes
TimeoutSec=infinity

[Install]
WantedBy=multi-user.target


And the Script itself:
Bash:
#!/bin/bash
parallel=4
pct list |grep stopped |awk '{print $1}' |  \
while read container; do
        # paralell x 4
        while [ $( jobs -pr | wc -l ) -ge ${parallel} ]
        do      sleep 0.5
        done
        # check if onboot yes/no
        onboot=$(pct config $container|grep onboot|awk '{print $2}')
          if [ "$onboot" == "1" ]; then
           pct start $container &
         sleep 0.5
        fi
done
 
  • Like
Reactions: oguz and fabian

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!