From 5ec3a71b945421da1e6a0df7b371990952cc6ead Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 5 Apr 2022 22:51:09 +0800 Subject: add some service actions --- xmake/modules/private/service/connect_service.lua | 28 ++++++++++++ .../modules/private/service/disconnect_service.lua | 28 ++++++++++++ xmake/modules/private/service/import_config.lua | 28 ++++++++++++ .../modules/private/service/reconnect_service.lua | 28 ++++++++++++ .../private/service/remote_build_server.lua | 52 ++++++++++++++++++++++ .../private/service/remote_build_server/main.lua | 52 ---------------------- xmake/modules/private/service/restart_service.lua | 30 +++++++++++++ xmake/modules/private/service/service.lua | 36 +++++++++++++++ xmake/modules/private/service/show_logs.lua | 27 +++++++++++ xmake/modules/private/service/show_status.lua | 27 +++++++++++ xmake/modules/private/service/start_service.lua | 33 ++++++++++++++ xmake/modules/private/service/stop_service.lua | 28 ++++++++++++ xmake/plugins/service/main.lua | 48 ++++++++++---------- xmake/plugins/service/service.lua | 36 --------------- xmake/plugins/service/xmake.lua | 16 ++++--- 15 files changed, 380 insertions(+), 117 deletions(-) create mode 100644 xmake/modules/private/service/connect_service.lua create mode 100644 xmake/modules/private/service/disconnect_service.lua create mode 100644 xmake/modules/private/service/import_config.lua create mode 100644 xmake/modules/private/service/reconnect_service.lua create mode 100644 xmake/modules/private/service/remote_build_server.lua delete mode 100644 xmake/modules/private/service/remote_build_server/main.lua create mode 100644 xmake/modules/private/service/restart_service.lua create mode 100644 xmake/modules/private/service/service.lua create mode 100644 xmake/modules/private/service/show_logs.lua create mode 100644 xmake/modules/private/service/show_status.lua create mode 100644 xmake/modules/private/service/start_service.lua create mode 100644 xmake/modules/private/service/stop_service.lua delete mode 100644 xmake/plugins/service/service.lua diff --git a/xmake/modules/private/service/connect_service.lua b/xmake/modules/private/service/connect_service.lua new file mode 100644 index 000000000..fc427d445 --- /dev/null +++ b/xmake/modules/private/service/connect_service.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file connect_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() + -- TODO +end + diff --git a/xmake/modules/private/service/disconnect_service.lua b/xmake/modules/private/service/disconnect_service.lua new file mode 100644 index 000000000..f39b29068 --- /dev/null +++ b/xmake/modules/private/service/disconnect_service.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file disconnect_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() + -- TODO +end + diff --git a/xmake/modules/private/service/import_config.lua b/xmake/modules/private/service/import_config.lua new file mode 100644 index 000000000..666d6c436 --- /dev/null +++ b/xmake/modules/private/service/import_config.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file import_config.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() + -- TODO +end + diff --git a/xmake/modules/private/service/reconnect_service.lua b/xmake/modules/private/service/reconnect_service.lua new file mode 100644 index 000000000..1032a3abe --- /dev/null +++ b/xmake/modules/private/service/reconnect_service.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file reconnect_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() + -- TODO +end + diff --git a/xmake/modules/private/service/remote_build_server.lua b/xmake/modules/private/service/remote_build_server.lua new file mode 100644 index 000000000..19e5f8c93 --- /dev/null +++ b/xmake/modules/private/service/remote_build_server.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file remote_build_server.lua +-- + +-- imports +import("private.service.server") + +-- define module +local remote_build_server = remote_build_server or server() +local super = remote_build_server:class() + +-- init server +function remote_build_server:init() + super.init(self) + super.handler_set(self, self.handler) +end + +-- the server handler +function remote_build_server:handler(sock) + print("on handler") +end + +-- get class +function remote_build_server:class() + return remote_build_server +end + +function remote_build_server:__tostring() + return "" +end + +function main() + local instance = remote_build_server() + instance:init() + return instance +end diff --git a/xmake/modules/private/service/remote_build_server/main.lua b/xmake/modules/private/service/remote_build_server/main.lua deleted file mode 100644 index 6409e6db3..000000000 --- a/xmake/modules/private/service/remote_build_server/main.lua +++ /dev/null @@ -1,52 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file main.lua --- - --- imports -import("private.service.server") - --- define module -local remote_build_server = remote_build_server or server() -local super = remote_build_server:class() - --- init server -function remote_build_server:init() - super.init(self) - super.handler_set(self, self.handler) -end - --- the server handler -function remote_build_server:handler(sock) - print("on handler") -end - --- get class -function remote_build_server:class() - return remote_build_server -end - -function remote_build_server:__tostring() - return "" -end - -function main() - local instance = remote_build_server() - instance:init() - return instance -end diff --git a/xmake/modules/private/service/restart_service.lua b/xmake/modules/private/service/restart_service.lua new file mode 100644 index 000000000..a21053801 --- /dev/null +++ b/xmake/modules/private/service/restart_service.lua @@ -0,0 +1,30 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file restart_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.stop_service") +import("private.service.start_service") + +function main() + stop_service(); + start_service({daemon = true}); +end + diff --git a/xmake/modules/private/service/service.lua b/xmake/modules/private/service/service.lua new file mode 100644 index 000000000..719cc8b0a --- /dev/null +++ b/xmake/modules/private/service/service.lua @@ -0,0 +1,36 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("core.base.scheduler") +import("private.service.remote_build_server") + +function _start_remote_build_server() + remote_build_server():runloop() +end + +function main() + local starters = {_start_remote_build_server} + for _, start_server in ipairs(starters) do + scheduler.co_start(start_server) + end +end + diff --git a/xmake/modules/private/service/show_logs.lua b/xmake/modules/private/service/show_logs.lua new file mode 100644 index 000000000..a0d3b7683 --- /dev/null +++ b/xmake/modules/private/service/show_logs.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file show_logs.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() +end + diff --git a/xmake/modules/private/service/show_status.lua b/xmake/modules/private/service/show_status.lua new file mode 100644 index 000000000..0a61fae7a --- /dev/null +++ b/xmake/modules/private/service/show_status.lua @@ -0,0 +1,27 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file show_status.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() +end + diff --git a/xmake/modules/private/service/start_service.lua b/xmake/modules/private/service/start_service.lua new file mode 100644 index 000000000..5ab440e9e --- /dev/null +++ b/xmake/modules/private/service/start_service.lua @@ -0,0 +1,33 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file start_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main(opt) + opt = opt or {} + if opt.daemon then + os.execv(os.programfile(), {"lua", "private.service.service"}, {detach = true}) + else + service() + end +end + diff --git a/xmake/modules/private/service/stop_service.lua b/xmake/modules/private/service/stop_service.lua new file mode 100644 index 000000000..723ca4416 --- /dev/null +++ b/xmake/modules/private/service/stop_service.lua @@ -0,0 +1,28 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file stop_service.lua +-- + +-- imports +import("core.base.option") +import("private.service.service") + +function main() + -- TODO +end + diff --git a/xmake/plugins/service/main.lua b/xmake/plugins/service/main.lua index 8e1ba8c4b..acf0540a4 100644 --- a/xmake/plugins/service/main.lua +++ b/xmake/plugins/service/main.lua @@ -20,38 +20,38 @@ -- imports import("core.base.option") -import("service") - -function _start_service(opt) - opt = opt or {} - if opt.daemon then - os.execv(os.programfile(), {"lua", path.join(os.scriptdir(), "service.lua")}, {detach = true}) - else - service() - end -end - -function _restart_service() -end - -function _show_service_logs() -end - -function _show_service_status() -end +import("private.service.start_service") +import("private.service.restart_service") +import("private.service.stop_service") +import("private.service.connect_service") +import("private.service.reconnect_service") +import("private.service.disconnect_service") +import("private.service.import_config") +import("private.service.show_logs") +import("private.service.show_status") function main() cprint("${color.warning}It's experimental feature, still in development!") if option.get("start") then - _start_service({daemon = true}) + start_service({daemon = true}) elseif option.get("restart") then - _restart_service() + restart_service() + elseif option.get("stop") then + stop_service() + elseif option.get("connect") then + connect_service() + elseif option.get("reconnect") then + reconnect_service() + elseif option.get("disconnect") then + disconnect_service() + elseif option.get("config") then + import_config() elseif option.get("logs") then - _show_service_logs() + show_logs() elseif option.get("status") then - _show_service_status() + show_status() else - _start_service() + start_service() end end diff --git a/xmake/plugins/service/service.lua b/xmake/plugins/service/service.lua deleted file mode 100644 index 719cc8b0a..000000000 --- a/xmake/plugins/service/service.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file main.lua --- - --- imports -import("core.base.option") -import("core.base.scheduler") -import("private.service.remote_build_server") - -function _start_remote_build_server() - remote_build_server():runloop() -end - -function main() - local starters = {_start_remote_build_server} - for _, start_server in ipairs(starters) do - scheduler.co_start(start_server) - end -end - diff --git a/xmake/plugins/service/xmake.lua b/xmake/plugins/service/xmake.lua index 024eca0d6..a84286c02 100644 --- a/xmake/plugins/service/xmake.lua +++ b/xmake/plugins/service/xmake.lua @@ -25,9 +25,15 @@ task("service") set_menu {usage = "xmake service [options]", description = "Start service for remote or distributed compilation and etc. ${color.warning}(Experimental, still in development)", options = { - {nil, "start", "k", nil, "Start daemon service." }, - {nil, "restart", "k", nil, "Restart daemon service." }, - {nil, "stop" , "k", nil, "Stop daemon service." }, - {nil, "logs", "k", nil, "Show service logs if the daemon service has been started." }, - {nil, "status", "k", nil, "Show service status if the daemon service has been started." } + {nil, "start", "k", nil, "Start daemon service." }, + {nil, "restart", "k", nil, "Restart daemon service." }, + {nil, "stop" , "k", nil, "Stop daemon service." }, + {nil, "connect" , "k", nil, "Connect the remote daemon service." }, + {nil, "reconnect", "k", nil, "Reconnect the remote daemon service." }, + {nil, "disconnect", "k", nil, "Disconnect the remote daemon service." }, + {nil, "config", "kv", nil, "Import the configuration file. (default: ~/.xmake/service/config.lua)", + "e.g.", + " - xmake service --config=/tmp/config.lua" }, + {nil, "logs", "k", nil, "Show service logs if the daemon service has been started." }, + {nil, "status", "k", nil, "Show service status if the daemon service has been started." } }} -- cgit v1.3.1