@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When `bin/drydock lease` is interrupted, release leases

Summary:
Depends on D19072. Ref T13073. Currently, you can leave leases stranded by using `^C` to interrupt the script. Handle signals and release leases on destruction if they haven't activated yet.

Also, print out more useful information before and after activation.

Test Plan: Mashed ^C while runnning `bin/drydock lease ... --trace`, saw the lease release.

Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13073

Differential Revision: https://secure.phabricator.com/D19073

+54 -8
+1 -1
scripts/drydock/drydock_control.php
··· 2 2 <?php 3 3 4 4 $root = dirname(dirname(dirname(__FILE__))); 5 - require_once $root.'/scripts/__init_script__.php'; 5 + require_once $root.'/scripts/init/init-script-with-signals.php'; 6 6 7 7 $args = new PhutilArgumentParser($argv); 8 8 $args->setTagline(pht('manage drydock software resources'));
+11
scripts/init/init-script-with-signals.php
··· 1 + <?php 2 + 3 + // Initialize a script that will handle signals. 4 + 5 + if (function_exists('pcntl_async_signals')) { 6 + pcntl_async_signals(true); 7 + } else { 8 + declare(ticks = 1); 9 + } 10 + 11 + require_once dirname(__FILE__).'/init-script.php';
+1 -1
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
··· 206 206 } 207 207 208 208 // Destroy the lease on the host. 209 - $lease->releaseOnDestruction(); 209 + $lease->setReleaseOnDestruction(true); 210 210 211 211 if ($lease->isActive()) { 212 212 // Destroy the working copy on disk.
+33 -3
src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
··· 84 84 $lease->setUntil($until); 85 85 } 86 86 87 + // If something fatals or the user interrupts the process (for example, 88 + // with "^C"), release the lease. We'll cancel this below, if the lease 89 + // actually activates. 90 + $lease->setReleaseOnDestruction(true); 91 + 92 + // TODO: This would probably be better handled with PhutilSignalRouter, 93 + // but it currently doesn't route SIGINT. We're initializing it to setup 94 + // SIGTERM handling and make eventual migration easier. 95 + $router = PhutilSignalRouter::getRouter(); 96 + pcntl_signal(SIGINT, array($this, 'didReceiveInterrupt')); 97 + 98 + $t_start = microtime(true); 87 99 $lease->queueForActivation(); 88 100 89 101 echo tsprintf( 90 - "%s\n", 102 + "%s\n\n __%s__\n\n%s\n", 103 + pht('Queued lease for activation:'), 104 + PhabricatorEnv::getProductionURI($lease->getURI()), 91 105 pht('Waiting for daemons to activate lease...')); 92 106 93 107 $this->waitUntilActive($lease); 94 108 109 + // Now that we've survived activation and the lease is good, make it 110 + // durable. 111 + $lease->setReleaseOnDestruction(false); 112 + $t_end = microtime(true); 113 + 95 114 echo tsprintf( 96 - "%s\n", 97 - pht('Activated lease "%s".', $lease->getID())); 115 + "%s\n\n %s\n\n%s\n", 116 + pht( 117 + 'Activation complete. This lease is permanent until manually '. 118 + 'released with:'), 119 + pht('$ ./bin/drydock release-lease --id %d', $lease->getID()), 120 + pht( 121 + 'Lease activated in %sms.', 122 + new PhutilNumber((int)(($t_end - $t_start) * 1000)))); 98 123 99 124 return 0; 100 125 } 101 126 127 + public function didReceiveInterrupt($signo) { 128 + // Doing this makes us run destructors, particularly the "release on 129 + // destruction" trigger on the lease. 130 + exit(128 + $signo); 131 + } 102 132 103 133 private function waitUntilActive(DrydockLease $lease) { 104 134 $viewer = $this->getViewer();
+7 -2
src/applications/drydock/storage/DrydockLease.php
··· 36 36 * a lease, as you don't need to explicitly handle exceptions to properly 37 37 * release the lease. 38 38 */ 39 - public function releaseOnDestruction() { 40 - $this->releaseOnDestruction = true; 39 + public function setReleaseOnDestruction($release) { 40 + $this->releaseOnDestruction = $release; 41 41 return $this; 42 42 } 43 43 ··· 434 434 } 435 435 436 436 return $this; 437 + } 438 + 439 + public function getURI() { 440 + $id = $this->getID(); 441 + return "/drydock/lease/{$id}/"; 437 442 } 438 443 439 444
+1 -1
src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php
··· 62 62 DrydockCommandInterface::INTERFACE_TYPE); 63 63 64 64 // No matter what happens here, destroy the lease away once we're done. 65 - $lease->releaseOnDestruction(true); 65 + $lease->setReleaseOnDestruction(true); 66 66 67 67 $operation->applyOperation($interface); 68 68