diff options
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | src/monitor/fwd.hpp | 37 | ||||
-rw-r--r-- | src/monitor/globals.cpp | 33 | ||||
-rw-r--r-- | src/monitor/globals.hpp | 33 | ||||
-rw-r--r-- | src/monitor/main.cpp | 243 | ||||
-rwxr-xr-x | tools/config.py | 8 |
7 files changed, 7 insertions, 361 deletions
diff --git a/Makefile.in b/Makefile.in index 32dc73b..006594a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -767,4 +767,4 @@ doc: ${DOC_PNGS} most: $(filter-out bin/${tmwa}-map.elf,${BINARIES}) magic: $(filter obj/map/magic%,${PDC_OBJECTS}) -common: $(filter-out %/lib.pdc.o obj/debug-debug/% %_test.pdc.o obj/login/% obj/char/% obj/map/% obj/admin/% obj/monitor/%,${PDC_OBJECTS}) +common: $(filter-out %/lib.pdc.o obj/debug-debug/% %_test.pdc.o obj/login/% obj/char/% obj/map/% obj/admin/%,${PDC_OBJECTS}) @@ -151,19 +151,19 @@ to installed files has begun. ####tmwa-monitor: +<DEPRECATED> Formerly known as `eathena-monitor`. An unmaintained tool whose job was to keep restarting the servers every time they crashed. It still builds in case anyone was using it, but it proved inflexible and has't really been kept up-to-date with our (TMW's) server-data, and besides, the server doesn't crash much now. +There are also a number of other Open Source programs that monitor +services already. -At some point I plan to rewrite it and ship a new conf file, unless -everyone agrees to use systemd, in which case I maybe can use that. - -In the mean time, there is a `run-all` script in the server-data repo -that starts the appropriate server for that config. On the main server, -we instead start the servers (and bots) individually in a tmux. +There is a `run-all` script in the server-data repo that starts the +appropriate server for that config. On the main server, we instead +start the servers (and bots) individually in a tmux. ####tmwa-admin: Formerly known as `ladmin` ("local"). diff --git a/src/monitor/fwd.hpp b/src/monitor/fwd.hpp deleted file mode 100644 index 6900e8e..0000000 --- a/src/monitor/fwd.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once -// monitor/fwd.hpp - list of type names for monitor nonserver -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program 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. -// -// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. - -#include "../sanity.hpp" - -#include "../strings/fwd.hpp" // rank 1 -#include "../io/fwd.hpp" // rank 4 -#include "../net/fwd.hpp" // rank 5 -#include "../mmo/fwd.hpp" // rank 6 -#include "../high/fwd.hpp" // rank 9 -// monitor/fwd.hpp is rank ∞ because it is an executable - - -namespace tmwa -{ -namespace monitor -{ - struct MonitorConf; -} // namespace monitor -} // namespace tmwa diff --git a/src/monitor/globals.cpp b/src/monitor/globals.cpp deleted file mode 100644 index 49e814d..0000000 --- a/src/monitor/globals.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "globals.hpp" -// globals.cpp - Evil global variables for tmwa-monitor. -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program 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. -// -// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. - -#include "monitor_conf.hpp" - -#include "../poison.hpp" - - -namespace tmwa -{ - namespace monitor - { - MonitorConf monitor_conf; - pid_t pid_login, pid_char, pid_map; - } // namespace monitor -} // namespace tmwa diff --git a/src/monitor/globals.hpp b/src/monitor/globals.hpp deleted file mode 100644 index aa797d3..0000000 --- a/src/monitor/globals.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -// globals.hpp - Evil global variables for tmwa-monitor. -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program 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. -// -// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. - -#include "fwd.hpp" - -#include <sys/types.h> - - -namespace tmwa -{ - namespace monitor - { - extern MonitorConf monitor_conf; - extern pid_t pid_login, pid_char, pid_map; - } // namespace monitor -} // namespace tmwa diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp deleted file mode 100644 index f21a4a7..0000000 --- a/src/monitor/main.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// monitor/main.cpp - Old daemon to restart servers when they crashed. -// -// Copyright © ???? Bartosz Waszak <waszi@evil.org.pl> -// Copyright © 2011-2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program 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. -// -// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. - -#include <sys/wait.h> - -#include <fcntl.h> -#include <unistd.h> - -#include <csignal> -#include <cstdlib> - -#include "../strings/mstring.hpp" -#include "../strings/astring.hpp" -#include "../strings/zstring.hpp" -#include "../strings/xstring.hpp" -#include "../strings/literal.hpp" - -#include "../io/cxxstdio.hpp" -#include "../io/fd.hpp" -#include "../io/line.hpp" - -#include "../mmo/config_parse.hpp" -#include "../mmo/version.hpp" - -#include "../net/timestamp-utils.hpp" - -#include "globals.hpp" -#include "monitor_conf.hpp" - -#include "../poison.hpp" - - -namespace tmwa -{ -namespace monitor -{ -static -AString make_path(XString base, XString path) -{ - MString m; - m += base; - m += '/'; - m += path; - return AString(m); -} - -static -pid_t start_process(ZString exec) -{ - const char *args[2] = {exec.c_str(), nullptr}; - pid_t pid = fork(); - if (pid == -1) - { - FPRINTF(stderr, "Failed to fork"_fmt); - return 0; - } - if (pid == 0) - { - DIAG_PUSH(); - DIAG_I(cast_qual); - execv(exec.c_str(), const_cast<char **>(args)); - DIAG_POP(); - perror("Failed to exec"); - kill(getppid(), SIGABRT); - exit(1); - } - return pid; -} - -// Kill all children with the same signal we got, then ourself. -static -void stop_process(int sig) -{ - if (pid_login) - kill(pid_login, sig); - if (pid_char) - kill(pid_char, sig); - if (pid_map) - kill(pid_map, sig); - DIAG_PUSH(); - DIAG_I(old_style_cast); - DIAG_I(zero_as_null_pointer_constant); - signal(sig, SIG_DFL); - DIAG_POP(); - raise(sig); -} - -static -bool monitor_config(io::Spanned<XString> key, io::Spanned<ZString> value) -{ - return parse_monitor_conf(monitor_conf, key, value); -} - -static -bool monitor_confs(io::Spanned<XString> key, io::Spanned<ZString> value) -{ - if (key.data == "monitor_conf"_s) - { - return load_config_file(value.data, monitor_config); - } - key.span.error("Unknown meta-key for monitor nonserver"_s); - return false; -} -} // namespace monitor -} // namespace tmwa - -int main(int argc, char *argv[]) -{ - using namespace tmwa; - using namespace tmwa::monitor; - // These are all the signals we are likely to get - // The shell handles stop/cont - signal(SIGTERM, stop_process); - signal(SIGINT, stop_process); - signal(SIGQUIT, stop_process); - signal(SIGABRT, stop_process); - - monitor_conf.workdir = make_path(ZString(strings::really_construct_from_a_pointer, getenv("HOME"), nullptr), "tmwserver"_s); - - ZString argv0 = ZString(strings::really_construct_from_a_pointer, argv[0], nullptr); - bool loaded_config_yet = false; - bool runflag = true; - - for (int ai = 1; ai < argc; ++ai) - { - ZString argvi = ZString(strings::really_construct_from_a_pointer, argv[ai], nullptr); - if (argvi.startswith('-')) - { - if (argvi == "--help"_s) - { - PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, - argv0); - exit(0); - } - else if (argvi == "--version"_s) - { - PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); - exit(0); - } - else - { - FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); - runflag = false; - } - } - else - { - loaded_config_yet = true; - runflag &= load_config_file(argvi, monitor_confs); - } - } - - if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-monitor.conf"_s, monitor_confs); - - if (!runflag) - exit(1); - - if (chdir(monitor_conf.workdir.c_str()) < 0) - { - perror("Failed to change directory"); - exit(1); - } - - PRINTF("Starting:\n"_fmt); - PRINTF("* workdir: %s\n"_fmt, monitor_conf.workdir); - PRINTF("* login_server: %s\n"_fmt, monitor_conf.login_server); - PRINTF("* char_server: %s\n"_fmt, monitor_conf.char_server); - PRINTF("* map_server: %s\n"_fmt, monitor_conf.map_server); - { - //make sure all possible file descriptors are free for use by the servers - //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem - io::FD fd = io::FD::sysconf_SC_OPEN_MAX(); - while ((fd = fd.prev()) > io::FD::stderr()) - { - if (fd.close() == 0) - FPRINTF(stderr, "close fd %d\n"_fmt, fd.uncast_dammit()); - } - fd = io::FD::open("/dev/null"_s, O_RDWR); - if (fd == io::FD()) - { - perror("open /dev/null"); - exit(1); - } - fd.dup2(io::FD::stdin()); - fd.dup2(io::FD::stdout()); - fd.close(); - } - while (1) - { - // write stuff to stderr - timestamp_seconds_buffer timestamp; - stamp_time(timestamp); - - if (!pid_login) - { - pid_login = start_process(monitor_conf.login_server); - FPRINTF(stderr, "[%s] forked login server: %lu\n"_fmt, - timestamp, static_cast<unsigned long>(pid_login)); - } - if (!pid_char) - { - pid_char = start_process(monitor_conf.char_server); - FPRINTF(stderr, "[%s] forked char server: %lu\n"_fmt, - timestamp, static_cast<unsigned long>(pid_char)); - } - if (!pid_map) - { - pid_map = start_process(monitor_conf.map_server); - FPRINTF(stderr, "[%s] forked map server: %lu\n"_fmt, - timestamp, static_cast<unsigned long>(pid_map)); - } - pid_t dead = wait(nullptr); - if (dead == -1) - { - perror("Failed to wait for child"); - exit(1); - } - if (pid_login == dead) - pid_login = 0; - if (pid_char == dead) - pid_char = 0; - if (pid_map == dead) - pid_map = 0; - } -} diff --git a/tools/config.py b/tools/config.py index a32e8ca..aeb4e99 100755 --- a/tools/config.py +++ b/tools/config.py @@ -419,7 +419,6 @@ def build_config(): admin_realm = rv.realm('src/admin') char_realm = rv.realm('src/char') map_realm = rv.realm('src/map') - monitor_realm = rv.realm('src/monitor') # confs login_conf = login_realm.conf() @@ -434,8 +433,6 @@ def build_config(): map_conf = map_realm.conf() battle_conf = map_realm.conf('battle') - monitor_conf = monitor_realm.conf() - # headers cstdint_sys = SystemHeader('cstdint') vector_sys = SystemHeader('vector') @@ -677,11 +674,6 @@ def build_config(): battle_conf.opt('itemheal_regeneration_factor', i32, '1') battle_conf.opt('mob_splash_radius', i32, '-1', min='-1') - monitor_conf.opt('login_server', RString, lit('./login-server')) - monitor_conf.opt('char_server', RString, lit('./char-server')) - monitor_conf.opt('map_server', RString, lit('./map-server')) - monitor_conf.opt('workdir', RString, '{}') # initialized specially - return rv def main(): |