Software / code / prosody
Comparison
util/startup.lua @ 10599:4f655918fef1
Merge 0.11->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 19 Jan 2020 15:34:28 +0000 |
| parent | 10532:19ec384eb782 |
| parent | 10597:25a3c8134b0a |
| child | 10601:d8b51833926b |
comparison
equal
deleted
inserted
replaced
| 10595:17bab303daf5 | 10599:4f655918fef1 |
|---|---|
| 11 | 11 |
| 12 local dependencies = require "util.dependencies"; | 12 local dependencies = require "util.dependencies"; |
| 13 | 13 |
| 14 local original_logging_config; | 14 local original_logging_config; |
| 15 | 15 |
| 16 local short_params = { D = "daemonize", F = "no-daemonize" }; | |
| 17 local value_params = { config = true }; | |
| 18 | |
| 19 function startup.parse_args() | |
| 20 local parsed_opts = {}; | |
| 21 | |
| 22 if #arg > 0 and arg[1] ~= "--config" then | |
| 23 while true do | |
| 24 local raw_param = arg[1]; | |
| 25 if not raw_param then | |
| 26 break; | |
| 27 end | |
| 28 | |
| 29 local prefix = raw_param:match("^%-%-?"); | |
| 30 if not prefix then | |
| 31 break; | |
| 32 elseif prefix == "--" and raw_param == "--" then | |
| 33 table.remove(arg, 1); | |
| 34 break; | |
| 35 end | |
| 36 local param = table.remove(arg, 1):sub(#prefix+1); | |
| 37 if #param == 1 then | |
| 38 param = short_params[param]; | |
| 39 end | |
| 40 | |
| 41 if not param then | |
| 42 print("Unknown command-line option: "..tostring(param)); | |
| 43 print("Perhaps you meant to use prosodyctl instead?"); | |
| 44 os.exit(1); | |
| 45 end | |
| 46 | |
| 47 local param_k, param_v; | |
| 48 if value_params[param] then | |
| 49 param_k, param_v = param, table.remove(arg, 1); | |
| 50 if not param_v then | |
| 51 print("Expected a value to follow command-line option: "..raw_param); | |
| 52 os.exit(1); | |
| 53 end | |
| 54 else | |
| 55 param_k, param_v = param:match("^([^=]+)=(.+)$"); | |
| 56 if not param_k then | |
| 57 if param:match("^no%-") then | |
| 58 param_k, param_v = param:sub(4), false; | |
| 59 else | |
| 60 param_k, param_v = param, true; | |
| 61 end | |
| 62 end | |
| 63 end | |
| 64 parsed_opts[param_k] = param_v; | |
| 65 end | |
| 66 end | |
| 67 prosody.opts = parsed_opts; | |
| 68 end | |
| 69 | |
| 16 function startup.read_config() | 70 function startup.read_config() |
| 17 local filenames = {}; | 71 local filenames = {}; |
| 18 | 72 |
| 19 local filename; | 73 local filename; |
| 20 if arg[1] == "--config" and arg[2] then | 74 if prosody.opts.config then |
| 21 table.insert(filenames, arg[2]); | 75 table.insert(filenames, prosody.opts.config); |
| 22 if CFG_CONFIGDIR then | 76 if CFG_CONFIGDIR then |
| 23 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); | 77 table.insert(filenames, CFG_CONFIGDIR.."/"..prosody.opts.config); |
| 24 end | 78 end |
| 25 table.remove(arg, 1); table.remove(arg, 1); | |
| 26 elseif os.getenv("PROSODY_CONFIG") then -- Passed by prosodyctl | 79 elseif os.getenv("PROSODY_CONFIG") then -- Passed by prosodyctl |
| 27 table.insert(filenames, os.getenv("PROSODY_CONFIG")); | 80 table.insert(filenames, os.getenv("PROSODY_CONFIG")); |
| 28 else | 81 else |
| 29 table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); | 82 table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); |
| 30 end | 83 end |
| 424 print(string.format("Unknown version (%s) of binary pposix module, expected %s", | 477 print(string.format("Unknown version (%s) of binary pposix module, expected %s", |
| 425 tostring(pposix._VERSION), want_pposix_version)); | 478 tostring(pposix._VERSION), want_pposix_version)); |
| 426 os.exit(1); | 479 os.exit(1); |
| 427 end | 480 end |
| 428 prosody.current_uid = pposix.getuid(); | 481 prosody.current_uid = pposix.getuid(); |
| 429 local arg_root = arg[1] == "--root"; | 482 local arg_root = prosody.opts.root; |
| 430 if arg_root then table.remove(arg, 1); end | |
| 431 if prosody.current_uid == 0 and config.get("*", "run_as_root") ~= true and not arg_root then | 483 if prosody.current_uid == 0 and config.get("*", "run_as_root") ~= true and not arg_root then |
| 432 -- We haz root! | 484 -- We haz root! |
| 433 local desired_user = config.get("*", "prosody_user") or "prosody"; | 485 local desired_user = config.get("*", "prosody_user") or "prosody"; |
| 434 local desired_group = config.get("*", "prosody_group") or desired_user; | 486 local desired_group = config.get("*", "prosody_group") or desired_user; |
| 435 local ok, err = pposix.setgid(desired_group); | 487 local ok, err = pposix.setgid(desired_group); |
| 534 end | 586 end |
| 535 end | 587 end |
| 536 | 588 |
| 537 -- prosodyctl only | 589 -- prosodyctl only |
| 538 function startup.prosodyctl() | 590 function startup.prosodyctl() |
| 591 startup.parse_args(); | |
| 539 startup.init_global_state(); | 592 startup.init_global_state(); |
| 540 startup.read_config(); | 593 startup.read_config(); |
| 541 startup.force_console_logging(); | 594 startup.force_console_logging(); |
| 542 startup.init_logging(); | 595 startup.init_logging(); |
| 543 startup.setup_plugindir(); | 596 startup.setup_plugindir(); |
| 555 end | 608 end |
| 556 | 609 |
| 557 function startup.prosody() | 610 function startup.prosody() |
| 558 -- These actions are in a strict order, as many depend on | 611 -- These actions are in a strict order, as many depend on |
| 559 -- previous steps to have already been performed | 612 -- previous steps to have already been performed |
| 613 startup.parse_args(); | |
| 560 startup.init_global_state(); | 614 startup.init_global_state(); |
| 561 startup.read_config(); | 615 startup.read_config(); |
| 562 startup.init_logging(); | 616 startup.init_logging(); |
| 563 startup.sanity_check(); | 617 startup.sanity_check(); |
| 564 startup.sandbox_require(); | 618 startup.sandbox_require(); |