This site is a static archive of the Aegir community site. Documentation has moved to http://docs.aegirproject.org. Other community resources can be found on the Contacting the community page.
Skip navigation

Is there a way to delete a platform from the command line?

Help

Is there a way to delete a platform from the command line?

Seems like there's a command to delete a site (provision-delete) and a context by passing --delete, but not the entire platform with all the files.

#1

Building off of comment #8,

here's a drush script which will automatically add a delete task to hostmaster and delete all platforms with a certain name, which are older than 2 days.

We use this as part of our "lite" continuous integration approach (which runs entirely using shell scripts) http://community.aegirproject.org/discuss/our-zero-touch-build-setup-con...

cleanup.drush

#!/usr/bin/env drush

<?php

//Cleanup script to delete empty autogenerated platforms older than 2 days

//Provide the platform location via the command line
$platform_location = drush_shift();

$sql = "SELECT n.nid FROM hosting_platform AS p
  INNER JOIN node AS n ON (p.nid=n.nid)
  LEFT JOIN hosting_site AS s ON (p.nid=s.platform)
  WHERE s.platform IS NULL AND n.created < (UNIX_TIMESTAMP() - 172800) AND p.publish_path LIKE '%%%s%%' AND p.status = 1;"
;

$result = db_query($sql, $platform_location);
while (
$row = db_fetch_array($result)) {
 
hosting_add_task($row['nid'], 'delete');
}

?>

Here's how to call it from the command line (make sure you're running it from a place where the @hostmaster context is available, like /var/aegir

cleanup.drush @hostmaster PREFIX

(where "PREFIX" is whatever name prefix you give your platforms that you want to automatically delete)

#2

@Gmania

Pretty cool, thanks

#3

Thanks for sharing!

#6

I'm using this for Aegir 7.x-3.x, here's the code:

<?php
function hosting_cron_delete_platforms_cron() {

 
$sql = "SELECT n.nid FROM hosting_platform AS p INNER JOIN node AS n ON (p.nid=n.nid) LEFT JOIN hosting_site AS s ON (p.nid=s.platform) WHERE s.platform IS NULL AND n.created < (UNIX_TIMESTAMP() - 86400) AND p.status = 1;";
 
$result = db_query($sql);

  foreach(
$result as $row) {
   
watchdog('hostmaster', 'Platform ' . $row->nid . ' will be deleted.');
   
hosting_add_task($row->nid, 'delete');
  }

 
$sql = "SELECT * FROM hosting_site_backups WHERE timestamp < (UNIX_TIMESTAMP() - 86400)";
 
$result = db_query($sql);

  foreach(
$result as $row) {
    if (
file_exists($row->filename)) {
     
watchdog('hostmaster', 'Site backup ' . $row->filename . ' will be deleted.');
     
hosting_add_task($row->site, 'backup-delete', array($row->filename));
     
hosting_site_delete_backup($row->bid);
    }
  }
}
?>

I will probably create a module with configurable options this weekend.

#4

I believe provision-delete will work on platform aliases... It's probably just a documentation bug that it specifies only sites.

#5

So, it's possible to make backup of platforms then ?

#7

@Pol I've create a sandbox for this itch a while ago, see https://www.drupal.org/sandbox/helmo/1283656

Need help?

Discussion

The discussion area lets your team communicate by posting updates and discussing issues. It is a great place for sharing progress, discussing challenges, and exploring ideas.