feat: rename set-startup command in set-boot
This commit is contained in:
parent
7303bc7580
commit
3abb18195f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.cuberc
|
.cuberc
|
||||||
.cubestartup
|
.cubestartup
|
||||||
|
.cubeboot
|
||||||
|
|||||||
@ -14,7 +14,7 @@ All servers are automatically started at boot
|
|||||||
|
|
||||||
- `/servers/ping-server`: allow a machine to respond to a `ping` command.
|
- `/servers/ping-server`: allow a machine to respond to a `ping` command.
|
||||||
- `/servers/cube-server`: allow a machine to be controllable via `cube`.
|
- `/servers/cube-server`: allow a machine to be controllable via `cube`.
|
||||||
- `/servers/cube-startup.lua`: `cube` startup script.
|
- `/servers/cube-boot.lua`: `cube` boot script.
|
||||||
|
|
||||||
## Programs
|
## Programs
|
||||||
- `router`: route messages (you need to setup a router to be able to use all `apis/net` based programs and libs)
|
- `router`: route messages (you need to setup a router to be able to use all `apis/net` based programs and libs)
|
||||||
|
|||||||
@ -6,7 +6,7 @@ local LIST_FILES = {
|
|||||||
-- servers
|
-- servers
|
||||||
'servers/ping-server.lua',
|
'servers/ping-server.lua',
|
||||||
'servers/cube-server.lua',
|
'servers/cube-server.lua',
|
||||||
'servers/cube-startup.lua',
|
'servers/cube-boot.lua',
|
||||||
-- programs
|
-- programs
|
||||||
'programs/router.lua', -- router is not in servers folder because he's not ran on every machines
|
'programs/router.lua', -- router is not in servers folder because he's not ran on every machines
|
||||||
'programs/ping.lua',
|
'programs/ping.lua',
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
local _VERSION = '1.4.0';
|
local _VERSION = '2.0.0';
|
||||||
local CUBE_CHANNEL = 64;
|
local CUBE_CHANNEL = 64;
|
||||||
|
|
||||||
local net = require('/apis/net')();
|
local net = require('/apis/net')();
|
||||||
@ -42,7 +42,7 @@ local function printUsage()
|
|||||||
print();
|
print();
|
||||||
print('\t\t\tcube ls');
|
print('\t\t\tcube ls');
|
||||||
print('\t\t\tcube configure');
|
print('\t\t\tcube configure');
|
||||||
print('\t\t\tcube set-startup <machineId> [command]')
|
print('\t\t\tcube set-boot <machineId> [command]')
|
||||||
print('\t\t\tcube reboot <machineId>')
|
print('\t\t\tcube reboot <machineId>')
|
||||||
print('\t\t\tcube deploy')
|
print('\t\t\tcube deploy')
|
||||||
print('\t\t\tcube version')
|
print('\t\t\tcube version')
|
||||||
@ -50,6 +50,11 @@ local function printUsage()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function printUsageCommand(commandName)
|
local function printUsageCommand(commandName)
|
||||||
|
local function setBootUsage()
|
||||||
|
print('\t\t\tcube set-boot <machineId> [command]')
|
||||||
|
print('Setup a startup shell command on a remote cube.')
|
||||||
|
end
|
||||||
|
|
||||||
local USAGES = {
|
local USAGES = {
|
||||||
ls = function()
|
ls = function()
|
||||||
print('\t\t\tcube ls');
|
print('\t\t\tcube ls');
|
||||||
@ -59,10 +64,12 @@ local function printUsageCommand(commandName)
|
|||||||
print('\t\t\tcube configure');
|
print('\t\t\tcube configure');
|
||||||
print('Setup remote slave cubes.')
|
print('Setup remote slave cubes.')
|
||||||
end,
|
end,
|
||||||
["set-startup"] = function()
|
["set-boot"] = setBootUsage,
|
||||||
print('\t\t\tcube set-startup <machineId> [command]')
|
["setboot"] = setBootUsage,
|
||||||
print('Setup a startup shell command on a remote cube.')
|
["set-start"] = setBootUsage,
|
||||||
end,
|
["setstart"] = setBootUsage,
|
||||||
|
["set-startup"] = setBootUsage,
|
||||||
|
["setstartup"] = setBootUsage,
|
||||||
reboot = function()
|
reboot = function()
|
||||||
print('\t\t\tcube reboot <machineId>')
|
print('\t\t\tcube reboot <machineId>')
|
||||||
print('Reboot a cube machine.');
|
print('Reboot a cube machine.');
|
||||||
@ -110,7 +117,32 @@ local rebootCommand = function(machineId)
|
|||||||
for k in ipairs(results) do
|
for k in ipairs(results) do
|
||||||
local packet = packets[k];
|
local packet = packets[k];
|
||||||
|
|
||||||
print('reboot machine \'' .. tostring(packet.sourceId) .. '\'.');
|
print('reboot machine \'' .. tostring(packet.sourceId) .. '\'');
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local setBootCommand = function(machineId, shellCommand)
|
||||||
|
if not machineId then
|
||||||
|
printUsageCommand('set-boot');
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, results, packets = net.sendMultipleRequests(CUBE_CHANNEL, 'set-boot', shellCommand, machineId);
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
error(results);
|
||||||
|
end
|
||||||
|
|
||||||
|
for k in ipairs(results) do
|
||||||
|
local packet = packets[k];
|
||||||
|
|
||||||
|
if shellCommand == nil or shellCommand == '' then
|
||||||
|
print('boot DELETED');
|
||||||
|
else
|
||||||
|
print('boot UPDATED');
|
||||||
|
end
|
||||||
|
|
||||||
|
rebootCommand(packet.sourceId);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,27 +168,12 @@ local COMMANDS = {
|
|||||||
configure = function()
|
configure = function()
|
||||||
print('not implemented yet.');
|
print('not implemented yet.');
|
||||||
end,
|
end,
|
||||||
["set-startup"] = function(machineId, shellCommand)
|
["set-boot"] = setBootCommand,
|
||||||
if not machineId then
|
["setboot"] = setBootCommand,
|
||||||
printUsageCommand('set-startup');
|
["set-start"] = setBootCommand,
|
||||||
return;
|
["setstart"] = setBootCommand,
|
||||||
end
|
["set-startup"] = setBootCommand,
|
||||||
|
["setstartup"] = setBootCommand,
|
||||||
local ok, results, packets = net.sendMultipleRequests(CUBE_CHANNEL, 'set-startup', shellCommand, machineId);
|
|
||||||
|
|
||||||
if not ok then
|
|
||||||
error(results);
|
|
||||||
end
|
|
||||||
|
|
||||||
for k in ipairs(results) do
|
|
||||||
local packet = packets[k];
|
|
||||||
|
|
||||||
print('changed startup script on machine \'' ..
|
|
||||||
tostring(packet.sourceId) .. '\' by \'' .. tostring(shellCommand or '') .. '\'');
|
|
||||||
|
|
||||||
rebootCommand(packet.sourceId);
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
reboot = rebootCommand,
|
reboot = rebootCommand,
|
||||||
deploy = function()
|
deploy = function()
|
||||||
print('not implemented yet.');
|
print('not implemented yet.');
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
local _VERSION = '1.1.0';
|
local _VERSION = '2.0.0';
|
||||||
|
|
||||||
local function trim(s)
|
local function trim(s)
|
||||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||||
@ -17,11 +17,11 @@ local function readFile(path)
|
|||||||
return contents
|
return contents
|
||||||
end
|
end
|
||||||
|
|
||||||
local startupCommand = trim(readFile('.cubestartup') or readFile('.cubestart') or "");
|
local startupCommand = trim(readFile('.cubeboot') or "");
|
||||||
|
|
||||||
|
|
||||||
if startupCommand ~= "" then
|
if startupCommand ~= "" then
|
||||||
print('cube-startup v' .. _VERSION .. ': execute \'' .. startupCommand .. '\'...');
|
print('cube-boot v' .. _VERSION .. ': execute \'' .. startupCommand .. '\'...');
|
||||||
shell.run(startupCommand);
|
shell.run(startupCommand);
|
||||||
else
|
else
|
||||||
print('cube-startup v' .. _VERSION .. ' no startup command detected.')
|
print('cube-startup v' .. _VERSION .. ' no startup command detected.')
|
||||||
@ -1,4 +1,4 @@
|
|||||||
local _VERSION = '1.0.0';
|
local _VERSION = '2.0.0';
|
||||||
|
|
||||||
local net = require('/apis/net')();
|
local net = require('/apis/net')();
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ local function writeFile(path, content)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getStartupCommand()
|
local function getStartupCommand()
|
||||||
return trim(readFile('.cubestartup') or "")
|
return trim(readFile('.cubeboot') or "")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ping event
|
-- ping event
|
||||||
@ -54,9 +54,9 @@ net.listenRequest(CUBE_CHANNEL, "reboot", function(_, reply)
|
|||||||
end, 0.1);
|
end, 0.1);
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- set-startup event
|
-- set-boot event
|
||||||
net.listenRequest(CUBE_CHANNEL, "set-startup", function(startupCommand, reply)
|
net.listenRequest(CUBE_CHANNEL, "set-boot", function(startupCommand, reply)
|
||||||
local res = writeFile('/.cubestartup', startupCommand);
|
local res = writeFile('/.cubeboot', startupCommand);
|
||||||
reply(res);
|
reply(res);
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ local _VERSION = '1.1.1'
|
|||||||
local SERVERS = {
|
local SERVERS = {
|
||||||
"servers/ping-server",
|
"servers/ping-server",
|
||||||
"servers/cube-server.lua",
|
"servers/cube-server.lua",
|
||||||
"servers/cube-startup.lua",
|
"servers/cube-boot.lua",
|
||||||
};
|
};
|
||||||
|
|
||||||
local function init()
|
local function init()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user