|
Bogdan Timofte
authored
3 months ago
|
1
|
# PGS - Technical Notes
|
|
|
2
|
|
|
|
3
|
## Rol
|
|
|
4
|
|
|
|
5
|
`pgs` ofera un flux manual si predictibil pentru:
|
|
|
6
|
- suspend to disk la VM-uri QEMU aflate in rulare
|
|
|
7
|
- shutdown graceful la containere LXC aflate in rulare
|
|
|
8
|
- resume/start dupa mentenanta pe baza unui state file local
|
|
|
9
|
|
|
|
10
|
## Comanda instalata
|
|
|
11
|
|
|
|
12
|
- locatie: `/usr/local/sbin/pgs`
|
|
|
13
|
- uninstall canonic: `/usr/local/lib/xdev/pve-guests-state/uninstall.sh`
|
|
|
14
|
- documentatie instalata: `/usr/local/share/doc/xdev/pve-guests-state`
|
|
|
15
|
|
|
|
16
|
## State runtime
|
|
|
17
|
|
|
|
18
|
- locatie curenta: `/var/lib/xdev/pve-guests-state/pgs-state.json`
|
|
|
19
|
- locatie legacy acceptata pentru migrare: `/var/lib/pve-manager/pgs-state.json`
|
|
|
20
|
- lock file: `/run/pgs.lock`
|
|
|
21
|
|
|
|
22
|
State file-ul contine:
|
|
|
23
|
- `timestamp`
|
|
|
24
|
- `hostname`
|
|
|
25
|
- `to_resume`
|
|
|
26
|
- `was_suspended`
|
|
|
27
|
- `ct_to_start`
|
|
|
28
|
- `vm_details`
|
|
|
29
|
- `mode`
|
|
|
30
|
- `suspend_volume`
|
|
|
31
|
- `suspend_file_date`
|
|
|
32
|
|
|
|
33
|
## Comenzi
|
|
|
34
|
|
|
|
35
|
```bash
|
|
|
36
|
/usr/local/sbin/pgs suspend [-v] [--dry-run]
|
|
|
37
|
/usr/local/sbin/pgs resume [-v] [--dry-run]
|
|
|
38
|
/usr/local/sbin/pgs cleanup [-v] [--dry-run]
|
|
|
39
|
```
|
|
|
40
|
|
|
|
41
|
## Comportament
|
|
|
42
|
|
|
|
43
|
### Suspend
|
|
|
44
|
|
|
|
45
|
- preflight cleanup pentru volume orphan/stale `vm-*-state-suspend-YYYY-MM-DD.raw`
|
|
|
46
|
- VM running -> `qm suspend --todisk 1` -> adaugat in `to_resume`
|
|
|
47
|
- VM paused/suspended RAM -> suspend to disk, dar nu intra in `to_resume`
|
|
|
48
|
- VM deja suspendat pe disk -> warning, fara auto-resume; detectia pentru disk suspend cere `lock: suspended`, `vmstate:` in config si un volum de saved-state rezolvabil in storage
|
|
|
49
|
- CT running -> `pct shutdown --timeout 120` -> adaugat in `ct_to_start`
|
|
|
50
|
- daca exista deja state file, un nou `suspend` face merge peste state-ul existent si pastreaza intentia anterioara de `to_resume`
|
|
|
51
|
- pentru fiecare VM retinut in state se salveaza si `suspend_volume` plus `suspend_file_date`
|
|
|
52
|
|
|
|
53
|
### Cleanup
|
|
|
54
|
|
|
|
55
|
- scaneaza storage-urile cu `content images` definite in `/etc/pve/storage.cfg`
|
|
|
56
|
- cauta exclusiv fisiere `vm-*-state-suspend-YYYY-MM-DD.raw`
|
|
|
57
|
- ignora fisiere de forma `vm-*-state-cp*.raw`
|
|
|
58
|
- daca un volum `state-suspend` este referit de un VM valid suspendat, il pastreaza
|
|
|
59
|
- daca un volum `state-suspend` este referit, dar VM-ul nu mai are stare valida de suspend, curata `lock`, `vmstate` si volumul
|
|
|
60
|
- daca un volum `state-suspend` nu mai este referit de niciun VM, il trateaza ca orphan si il sterge
|
|
|
61
|
|
|
|
62
|
### Resume
|
|
|
63
|
|
|
|
64
|
- VMs din `to_resume` -> `qm resume`
|
|
|
65
|
- CTs din `ct_to_start` -> `pct start`
|
|
|
66
|
- daca `suspend_volume` curent nu mai corespunde cu cel din state, VM-ul este tratat ca alterat dupa salvarea state-ului si nu este auto-resumat
|
|
|
67
|
- daca apar esecuri, state file-ul ramane pentru retry
|
|
|
68
|
- daca totul reuseste, state file-ul este sters
|
|
|
69
|
|
|
|
70
|
## Protectii implementate
|
|
|
71
|
|
|
|
72
|
- stale suspend image cleanup
|
|
|
73
|
- cleanup pentru volume orphan `vm-*-state-suspend-YYYY-MM-DD.raw`
|
|
|
74
|
- retry dupa erori specifice de quorum
|
|
|
75
|
- `pvecm expected 1` in fereastra de mentenanta, cand eroarea indica lipsa de quorum
|
|
|
76
|
- cleanup pentru `lock: suspended` cand VM-ul este deja running
|
|
|
77
|
- cleanup pentru artefacte stale de suspend pe VM-uri `stopped`: `lock: suspended`, `vmstate:` ramas in config si volume orphaned de saved-state
|
|
|
78
|
- lock local pentru a preveni rulari concurente
|
|
|
79
|
|
|
|
80
|
## Logging
|
|
|
81
|
|
|
|
82
|
- interactiva: output pe terminal
|
|
|
83
|
- prin systemd/journal stream: evitarea dublarii mesajelor in journal
|
|
|
84
|
- tag jurnal: `pgs`
|
|
|
85
|
|
|
|
86
|
Exemple:
|
|
|
87
|
|
|
|
88
|
```bash
|
|
|
89
|
journalctl -t pgs -n 50 --no-pager
|
|
|
90
|
journalctl -t pgs -f
|
|
|
91
|
```
|
|
|
92
|
|
|
|
93
|
## Note de design
|
|
|
94
|
|
|
|
95
|
- proiectul nu mai foloseste unitati systemd pentru execuție automata
|
|
|
96
|
- fisierele din `systemd/` sunt legacy si nu fac parte din install-ul curent
|
|
|
97
|
- proiectul nu are inca propriul config persistent in `/etc/xdev/...`
|