Skip to content

Commit

Permalink
Delete existing, non-running, service instead of deleting it
Browse files Browse the repository at this point in the history
Hoping that when the PR moby/moby#45107
will be realeased we don't get infinite orphaned tasks on the swarm.
  • Loading branch information
mmenozzi committed Mar 21, 2023
1 parent a8fbf19 commit fe2b06e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions swarm-cron
Original file line number Diff line number Diff line change
Expand Up @@ -141,34 +141,30 @@ function run(string $service, string $command): int {
}

try {
if ($cronServiceVersion === null) {
$client->request('POST', 'services/create', [
'json' => $cronServiceSpec,
if ($cronServiceVersion !== null) {
$client->request('DELETE', 'services/' . $cronServiceName, [
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock'
]
]);
$logger->info(
sprintf(
'Started cron service "%s" with command "%s" from service "%s"',
'Deleted old, not-running, cron service "%s" with command "%s" from service "%s"',
$cronServiceName,
$command,
$service
)
);
return 0;
}

$client->request('POST', 'services/' . $cronServiceName . '/update', [
'query' => ['version' => $cronServiceVersion],
$client->request('POST', 'services/create', [
'json' => $cronServiceSpec,
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock'
]
]);
$logger->info(
sprintf(
'Re-started cron service "%s" with command "%s" from service "%s"',
'Started cron service "%s" with command "%s" from service "%s"',
$cronServiceName,
$command,
$service
Expand Down

0 comments on commit fe2b06e

Please sign in to comment.