INSTALLEDMODULES = $(PREFIX)/lib/prosody/modules
INSTALLEDDATA = $(DATADIR)
-all: prosody.install prosody.cfg.lua.install
+all: prosody.install prosodyctl.install prosody.cfg.lua.install
$(MAKE) -C util-src install
-install: prosody.install prosody.cfg.lua.install util/encodings.so util/encodings.so util/pposix.so util/signal.so
+install: prosody.install prosodyctl.install prosody.cfg.lua.install util/encodings.so util/encodings.so util/pposix.so util/signal.so
install -d $(BIN) $(CONFIG) $(MODULES) $(SOURCE) $(DATA)
install -d $(CONFIG)/certs
install -d $(SOURCE)/core $(SOURCE)/net $(SOURCE)/util
install ./prosody.install $(BIN)/prosody
+ install ./prosodyctl.install $(BIN)/prosodyctl
install -m644 core/* $(SOURCE)/core
install -m644 net/* $(SOURCE)/net
install -m644 util/* $(SOURCE)/util
clean:
rm -f prosody.install
+ rm -f prosodyctl.install
rm -f prosody.cfg.lua.install
$(MAKE) clean -C util-src
s|^CFG_DATADIR=.*;$$|CFG_DATADIR='$(INSTALLEDDATA)';|; \
s|^CFG_PLUGINDIR=.*;$$|CFG_PLUGINDIR='$(INSTALLEDMODULES)/';|;" < prosody > prosody.install
+prosodyctl.install: prosodyctl
+ sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \
+ s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|; \
+ s|^CFG_DATADIR=.*;$$|CFG_DATADIR='$(INSTALLEDDATA)';|; \
+ s|^CFG_PLUGINDIR=.*;$$|CFG_PLUGINDIR='$(INSTALLEDMODULES)/';|;" < prosodyctl > prosodyctl.install
+
prosody.cfg.lua.install:
sed 's|certs/|$(INSTALLEDCONFIG)/certs/|' prosody.cfg.lua.dist > prosody.cfg.lua.install
end
end
-
+local components_loaded_once;
function load_enabled_components(config)
local defined_hosts = config or configmanager.getconfig();
if not ok then
log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
else
- log("info", "Activated %s component: %s", host_config.core.component_module, host);
+ log("debug", "Activated %s component: %s", host_config.core.component_module, host);
end
end
end
module "hostmanager"
+local hosts_loaded_once;
+
local function load_enabled_hosts(config)
local defined_hosts = config or configmanager.getconfig();
end
end
eventmanager.fire_event("hosts-activated", defined_hosts);
+ hosts_loaded_once = true;
end
eventmanager.add_event_hook("server-starting", load_enabled_hosts);
function activate(host, host_config)
hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
- log("info", "Activated host: %s", host);
+ log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host);
eventmanager.fire_event("host-activated", host, host_config);
end
-- Load modules when a host is activated
function load_modules_for_host(host)
+ if config.get(host, "core", "modules_enable") == false then
+ return; -- Only load for hosts, not components, etc.
+ end
+
-- Load modules from global section
local modules_enabled = config.get("*", "core", "modules_enabled");
local modules_disabled = config.get(host, "core", "modules_disabled");
function register(name, listener)
if listeners[name] and listeners[name] ~= listener then
- log("warn", "Listener %s is already registered, not registering any more", name);
+ log("debug", "Listener %s is already registered, not registering any more", name);
return false;
end
listeners[name] = listener;
- log("info", "Registered connection listener %s", name);
+ log("debug", "Registered connection listener %s", name);
return true;
end
local addtimer\r
local closeall\r
local addserver\r
+local getserver\r
local wrapserver\r
local getsettings\r
local closesocket\r
return handler\r
end\r
\r
+getserver = function ( port )\r
+ return _server[ port ];\r
+end\r
+\r
removeserver = function( port )\r
local handler = _server[ port ]\r
if not handler then\r
return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen\r
end\r
\r
-local dontstop = true;\r
+local dontstop = true; -- thinking about tomorrow, ...\r
\r
setquitting = function (quit)\r
dontstop = not quit;\r
closeall = closeall,\r
addtimer = addtimer,\r
addserver = addserver,\r
+ getserver = getserver,\r
getsettings = getsettings,\r
setquitting = setquitting,\r
removeserver = removeserver,\r
module.host = "*"; -- we're a global module
+-- Don't even think about it!
+module:add_event_hook("server-starting", function ()
+ if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then
+ module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!");
+ module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root");
+ _G.prosody_shutdown("Refusing to run as root");
+ end
+ end);
+
local pidfile_written;
local function remove_pidfile()
----------- End of out-of-place code --------------
+-- Global function to initiate prosody shutdown
+function prosody_shutdown(reason)
+ log("info", "Shutting down: %s", reason or "unknown reason");
+ eventmanager.fire_event("server-stopping", { reason = reason });
+ server.setquitting(true);
+end
+
+-- Signal to modules that we are ready to start
eventmanager.fire_event("server-starting");
+-- Load SSL settings from config, and create a ctx table
local global_ssl_ctx = ssl and config.get("*", "core", "ssl");
if global_ssl_ctx then
local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
cl.start("console", { interface = config.get("*", "core", "console_interface") or "127.0.0.1" })
end
--- Global function to initiate prosody shutdown
-function prosody_shutdown(reason)
- log("info", "Shutting down: %s", reason or "unknown reason");
- eventmanager.fire_event("server-stopping", { reason = reason });
- server.setquitting(true);
-end
-
-- Catch global accesses --
local locked_globals_mt = { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end }
-- need to do some tidying before we go :)
server.setquitting(false);
+log("info", "Shutdown status: Closing all active sessions");
for hostname, host in pairs(hosts) do
- log("info", "Shutdown status: Closing client connections for %s", hostname)
+ log("debug", "Shutdown status: Closing client connections for %s", hostname)
if host.sessions then
for username, user in pairs(host.sessions) do
for resource, session in pairs(user.sessions) do
end
end
- log("info", "Shutdown status: Closing outgoing s2s connections from %s", hostname);
+ log("debug", "Shutdown status: Closing outgoing s2s connections from %s", hostname);
if host.s2sout then
for remotehost, session in pairs(host.s2sout) do
if session.close then
return 1;
end
-function commands.start()
+function commands.start(arg)
+ if arg[1] == "--help" then
+ show_usage([[start]], [[Start Prosody]]);
+ return 1;
+ end
local ok, ret = prosodyctl.isrunning();
if not ok then
show_message(error_messages[ret]);
return 1;
end
-function commands.status()
+function commands.status(arg)
+ if arg[1] == "--help" then
+ show_usage([[status]], [[Reports the running status of Prosody]]);
+ return 1;
+ end
+
local ok, ret = prosodyctl.isrunning();
if not ok then
show_message(error_messages[ret]);
end
show_message("Prosody is running with PID %s", ret or "(unknown)");
return 0;
+ else
+ show_message("Prosody is not running");
+ return 2
end
return 1;
end
-function commands.stop()
+function commands.stop(arg)
+ if arg[1] == "--help" then
+ show_usage([[stop]], [[Stop a running Prosody server]]);
+ return 1;
+ end
+
if not prosodyctl.isrunning() then
show_message("Prosody is not running");
return 1;
local ok, ret = prosodyctl.stop();
if ok then return 0; end
- show_message(error_messages[ret])
+ show_message(error_messages[ret]);
return 1;
end
------- API -------------
function set_data_path(path)
- log("info", "Setting data path to: %s", path);
+ log("debug", "Setting data path to: %s", path);
data_path = path;
end
function set_callback(func)