56 lines
1.6 KiB
Lua
56 lines
1.6 KiB
Lua
local createCloud = require('/apis/libcloud');
|
|
local createVersion = require('/apis/libversion');
|
|
|
|
local URL_SETTING = 'cloud.url';
|
|
|
|
local rawArgs = table.pack(...);
|
|
local command = rawArgs[1];
|
|
|
|
local function printUsage()
|
|
print('cloud usage:');
|
|
print();
|
|
print(' cloud health');
|
|
print(' cloud --version');
|
|
print(' cloud --help');
|
|
print();
|
|
print('settings required:');
|
|
print(' cloud.url (gateway origin, e.g. ws://host:4444)');
|
|
print('settings optional:');
|
|
print(' cloud.password (shared secret for the hello handshake)');
|
|
end
|
|
|
|
if command == '--version' or command == '-version' or command == 'version' or command == '-v' then
|
|
print('v' .. createVersion().forSelf());
|
|
return;
|
|
end
|
|
|
|
if command == '--help' or command == '-help' or command == 'help' or command == '-h' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
if command == 'health' then
|
|
local url = settings.get(URL_SETTING);
|
|
if type(url) ~= 'string' or url == '' then
|
|
print('set cloud.url first');
|
|
return;
|
|
end
|
|
|
|
local ok, result = createCloud().request('probe_server');
|
|
if not ok then
|
|
local code = (type(result) == 'table' and result.code) or 'internal';
|
|
local message = (type(result) == 'table' and result.message) or '';
|
|
print('cloud health failed: ' .. tostring(code) .. ' ' .. tostring(message));
|
|
return;
|
|
end
|
|
|
|
print('serverOk: ' .. tostring(result.serverOk));
|
|
print('opencodeOk: ' .. tostring(result.opencodeOk));
|
|
if not result.opencodeOk and result.opencodeDetail then
|
|
print('opencode: ' .. tostring(result.opencodeDetail));
|
|
end
|
|
return;
|
|
end
|
|
|
|
printUsage();
|