Run Systemd service after proxmox finished starting?

Dunuin

Distinguished Member
Jun 30, 2020
14,219
4,162
243
Germany
Hi,

I wrote a script that will unlock my encrypted datasets, mount some SMB shares and start VMs afterwards.
I would like this script to be autorun by a systemd service but I'm not sure what to set for "AFTER" and "REQUIRE" so it will only be started after proxmox finished everything like starting networks, initializing zfs pools and so on.

Someone knows what values to use for "AFTER" and "REQUIRE"?
Is there a proxmox target I can use for "AFTER" to be sure proxmox has finished booting?

I thought this might look like this:
Code:
[Unit]
Description=PVE Start Script
Requires=network.target zfs.target local-fs.target remote-fs.target
After=pve-guests.service

[Service]
Type=oneshot
ExecStart=/bin/bash /root/scripts/start.sh
User=root

[Install]
WantedBy=multi-user.target
 
Last edited:
You can use systemd-analyze plot > image.svg or systemd-analyze critical-chain to get a good overview of starting services.

pve-guests.service is the last PVE service to start, and indicates everything is ready (this is the service that handles 'onboot' auto-start for VMs and CTs). In your case it might also be enough to just go after zfs.target, or pve-cluster.service (or pve-ha-lrm.service if you use HA).
 
  • Like
Reactions: Dunuin
Thanks,

It finally works after months. Now I just need open a SSH shell, type in my LUKS passphrase and it automatically unlocks all the encrypted zfs datasets, mounts the SMB shares and starts the VMs and LXCs in the right order. :)

I used this systemd script:
Code:
[Unit]
Description=PVE Start Script
After=pve-guests.service

[Service]
Type=oneshot
ExecStart=/bin/bash /root/scripts/start.sh
User=root

[Install]
WantedBy=multi-user.target
 
  • Like
Reactions: Stefan_R

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!