Support of SlapOS prerm scripts¶
The goal of this document is to how the prerm script on SlapOS which runs when the partition is going to be destroyed
Table of Contents
Introduction¶
Prerm extension on SlapOS was introduced from slapos node version 1.4.1. When the module is enabled on slapos server, this allow the partition to define a script which will be executed by slapgrid only when the partition is being destroyed.
How slapos prerm works¶
The software release should put the script to execute into the folder partition_root/etc/prerm. A good example of script is the one used in kvm which wipe vm images disk: https://lab.nexedi.com/nexedi/slapos.toolbox/blob/master/slapos/securedelete.py.
The prerm script is invoked by slapgrid before destroy the partition. This is the sequence of partition destruction:
- Slapgrid stop the partition: prepare the destruction, stop all processes first
- check retention delay lock: if there is a retention delay, which prevent partition destruction at the moment, stop here (no prerm script will run).
- Add all prerm scripts to supervisord and start them. They will be added in a new supervisord process group named 'slappartID-prerm' where ID is the number of the partition. To check all processes stated by prerm, use the command:
slapos node status slappartID-prerm:
- check if prerm script are exited: when one of prerm scripts is running the partition will not be destroyed, slapgrid will wait until they are all stopped or exited.
- destroy the partition: Slapgrid will cleanup supervisord and remove all files from the partition.
This is the sample of destruction of slappart98. The prerm script 'slapos_wipe_qemu_disk' is started here, then destruction process is stopped because we have a prerm script running. The script 'slapos_wipe_qemu_disk' continue to run in background.
[2017-10-05 10:55:11,900] INFO Requested stop of slappart98...
[2017-10-05 10:55:11,950] INFO Adding pre-delete scripts to supervisord...
[2017-10-05 10:55:11,952] DEBUG Updating supervisord
[2017-10-05 10:55:12,018] INFO Updated 'slappart98-prerm'
[2017-10-05 10:55:12,018] DEBUG Supervisord updated
[2017-10-05 10:55:12,020] INFO Starting pre-delete process u'slapos_wipe_qemu_disk'...
[2017-10-05 10:55:12,026] INFO There are running processes into the partition, wait until they finish...
If we check partition's processes status, we have the result bellow. The wipe script is running.
slappart98:6tunnel-cluster-on-watch STOPPED Oct 05 02:10 PM
slappart98:bootstrap-monitor EXITED Oct 05 01:55 PM
slappart98:certificate_authority-on-watch STOPPED Oct 05 02:10 PM
slappart98:crond-on-watch STOPPED Oct 05 02:10 PM
slappart98:http-server-on-watch STOPPED Oct 05 02:10 PM
slappart98:kvm-on-watch STOPPED Oct 05 02:10 PM
slappart98:kvm_controller EXITED Oct 05 01:55 PM
slappart98:monitor-httpd-graceful EXITED Oct 05 01:55 PM
slappart98:monitor-httpd-on-watch STOPPED Oct 05 02:10 PM
slappart98:websockify-on-watch STOPPED Oct 05 02:10 PM
slappart98-prerm:slapos_wipe_qemu_disk RUNNING pid 3375, uptime 0:00:06
Then after the prerm script is finished, slapos node report will have this result:
[2017-10-05 11:25:07,891] INFO Requested stop of slappart98...
[2017-10-05 11:25:07,957] INFO Adding pre-delete scripts to supervisord...
[2017-10-05 11:25:07,959] DEBUG Updating supervisord
[2017-10-05 11:25:08,003] DEBUG Supervisord updated
[2017-10-05 11:25:08,007] INFO Destroying Computer Partition slappart98...
[2017-10-05 11:25:08,015] DEBUG Updating supervisord
[2017-10-05 11:25:08,048] INFO Stopped 'slappart98'
[2017-10-05 11:25:08,049] INFO Removed 'slappart98'
[2017-10-05 11:25:08,050] INFO Stopped 'slappart98-prerm'
[2017-10-05 11:25:08,051] INFO Removed 'slappart98-prerm'
[2017-10-05 11:25:08,051] DEBUG Supervisord updated
[2017-10-05 11:25:08,453] INFO Finished usage reports.
Now the partition is destroyed.
How to enable prerm extension¶
Edit the slapos configuration in /etc/opt/slapos/slapos.cfg then add 'prerm' in manaer_list.
[slapos]
computer_id = COMP-XXX
...
manager_list = prerm
Related Articles¶