-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This option allows users to suspend execution of the cloud-init provisioning until a valid network is detected. This detection is currently done through requesting a DNS lookup for one of the Clear Linux NTP service IP addresses (this is a RR record, we don't actually look at the result). This lookup is not infinite. After 5 minutes, the wait exits no matter what even if there is no network detected. The option can be provided manually. `packages` and `package_upgrade` options *imply* this option, but one can explicitly disable the wait by providing it early in the cloud-config file with a value of `false`. The wait routing is active - it will retry relatively quickly to detect an active connection. Any failure will result in another retry. In a fully private network without public DNS, this will not work. The DNS hostname used for testing can be manipulated through the `-with-dnstestaddr=<hostname>` configure flag. You shouldn't put an IP address in here, since that fully disables any network testing.
- Loading branch information
Showing
10 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*** | ||
Copyright © 2019 Intel Corporation | ||
Author: Auke-jan H. Kok <[email protected]> | ||
This file is part of micro-config-drive. | ||
micro-config-drive is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
micro-config-drive is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with micro-config-drive. If not, see <http://www.gnu.org/licenses/>. | ||
In addition, as a special exception, the copyright holders give | ||
permission to link the code of portions of this program with the | ||
OpenSSL library under certain conditions as described in each | ||
individual source file, and distribute linked combinations | ||
including the two. | ||
You must obey the GNU General Public License in all respects | ||
for all of the code used other than OpenSSL. If you modify | ||
file(s) with this exception, you may extend this exception to your | ||
version of the file(s), but you are not obligated to do so. If you | ||
do not wish to do so, delete this exception statement from your | ||
version. If you delete this exception statement from all source | ||
files in the program, then also delete it here. | ||
***/ | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <netdb.h> | ||
#include <unistd.h> | ||
|
||
#include <glib.h> | ||
|
||
#include "handlers.h" | ||
#include "cloud_config.h" | ||
#include "lib.h" | ||
|
||
#define MOD "package_upgrade: " | ||
|
||
static int do_network_wait = -1; | ||
// -1: default: unset | ||
// 0: don't wait | ||
// 1: wait | ||
// 2: wait already happened | ||
|
||
void wait_for_network(void) { | ||
if (do_network_wait == 1) { | ||
struct hostent *he = NULL; | ||
useconds_t slept = 0; | ||
useconds_t times = 0; | ||
|
||
// don't re-enter | ||
do_network_wait = 2; | ||
|
||
memset(he, 0, sizeof(struct hostent)); | ||
LOG(MOD "Waiting for an active network connection.\n"); | ||
for (;;) { | ||
he = gethostbyname(DNSTESTADDR); | ||
if (he) { | ||
LOG(MOD "Network appears active, waiting completed.\n"); | ||
break; | ||
} | ||
times = times < 10 ? times + 1 : times; | ||
slept += times; | ||
if (slept > 3000) { | ||
LOG(MOD "Waited for network for 5 minutes, no answer - giving up.\n"); | ||
break; | ||
} | ||
usleep(times * 100000); | ||
} | ||
} | ||
} | ||
|
||
void wait_for_network_handler(GNode *node) { | ||
bool do_wait; | ||
|
||
LOG(MOD "Wait System Software Update Handler running...\n"); | ||
GNode* val = g_node_first_child(node); | ||
if (!val) { | ||
LOG(MOD "Corrupt userdata!\n"); | ||
return; | ||
} | ||
if (!cloud_config_bool(val, &do_wait)) { | ||
return; | ||
} | ||
|
||
if (do_wait) { | ||
do_network_wait = 1; | ||
wait_for_network(); | ||
} else { | ||
do_network_wait = 0; | ||
LOG(MOD "Disabling network wait.\n"); | ||
} | ||
} | ||
|
||
struct cc_module_handler_struct wait_for_network_cc_module = { | ||
.name = "wait_for_network", | ||
.handler = &wait_for_network_handler | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters