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
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.
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:
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.
Edit the slapos configuration in /etc/opt/slapos/slapos.cfg then add 'prerm' in manaer_list.
computer_id = COMP-XXX... manager_list = prerm
computer_id = COMP-XXX
manager_list = prerm