z_sites_manager (zotonic_core v1.0.0-rc.17)

Server managing all sites running inside Zotonic. Starts the sites according to the config files in the sites subdirectories. Handles scanning of all site directories for config files.

Summary

Functions

Wait for a site to complete its startup sequence.

Convert process state when code is changed

Scan all sites subdirectories for the site configurations.

Called by the zotonic_filehandler after a file has been changed. This relays the file change event to all sites using the #filewatcher{} event.

Do something for all sites that are currently running.

The list of builtin sites, they are located in the zotonic/apps/ directory.

Return the name of the site to handle unknown Host requests

Fetch the configuration of a specific site.

Set extra configurations for a site. Will overlay the read configuration when the site is started.

Return a list of contexts for all running sites.

Get the status of a particular site

Return a list of all sites and their current running status. This is coming from the ets table, so might be a bit delayed.

Return a list of all sites, their current running status and their hosts configs

Return information on all running sites.

Initiates the server.

Return true iff all sites are running. Don't count sites manually stopped.

Tell the sites manager that a module was loaded, check changes to observers, schema.

Override a given site config with arbitrary key/value pairs. Should be called before the site is started.

Let the sites manager reload the configuration of a site.

Restart a site or multiple sites.

Set the status of a site, called by the site supervisor

Start a site or multiple sites.

Starts the server

Stop a site or multiple sites.

This function is called by a gen_server when it is about to terminate.

Sync the supervised sites with the sites in the sites directory. Removes and stops deleted sites, adds (but does not start) new sites.

Wait for a site to be running, max 30 secs.

Types

site_status/0

-type site_status() :: new | starting | running | stopping | retrying | failed | stopped | removing.

Functions

await_startup(Context)

-spec await_startup(z:context() | atom()) ->
                       ok | {error, bad_name | failed | removing | stopped | stopping}.

Wait for a site to complete its startup sequence.

code_change(OldVsn, State, Extra)

-spec code_change(term(), term(), term()) -> {ok, term()}.

Convert process state when code is changed

do_scan_sites()

-spec do_scan_sites() -> #{Site :: atom() => proplists:proplist()}.

Scan all sites subdirectories for the site configurations.

do_scan_sites(_)

filechanged_observer(Zotonic_filehandler_filechange, CallContext)

-spec filechanged_observer(#zotonic_filehandler_filechange{verb :: modify | create | delete,
                                                           file :: binary(),
                                                           basename :: binary(),
                                                           extension :: binary()},
                           term()) ->
                              ok.

Called by the zotonic_filehandler after a file has been changed. This relays the file change event to all sites using the #filewatcher{} event.

foreach(Fun)

-spec foreach(fun((z:context()) -> any())) -> ok.

Do something for all sites that are currently running.

get_builtin_sites()

-spec get_builtin_sites() -> [atom()].

The list of builtin sites, they are located in the zotonic/apps/ directory.

get_fallback_site()

-spec get_fallback_site() -> atom() | undefined.

Return the name of the site to handle unknown Host requests

get_site_config(Site)

-spec get_site_config(atom()) -> {ok, list()} | {error, bad_name | term()}.

Fetch the configuration of a specific site.

get_site_config_overrides(Site)

-spec get_site_config_overrides(Site) -> List when Site :: atom(), List :: proplists:proplist().

Set extra configurations for a site. Will overlay the read configuration when the site is started.

get_site_contexts()

-spec get_site_contexts() -> [z:context()].

Return a list of contexts for all running sites.

get_site_status(Context)

-spec get_site_status(z:context() | atom()) -> {ok, site_status()} | {error, bad_name}.

Get the status of a particular site

get_sites()

-spec get_sites() -> #{atom() => site_status()}.

Return a list of all sites and their current running status. This is coming from the ets table, so might be a bit delayed.

get_sites_hosts()

-spec get_sites_hosts() ->
                         {ok, #{atom() => {site_status(), [{Host :: binary(), Prio :: pos_integer()}]}}}.

Return a list of all sites, their current running status and their hosts configs

handle_call(Message, From, State)

Return all sites

handle_cast(Message, State)

-spec handle_cast(term(), term()) ->
                     {noreply, term()} |
                     {noreply, term(), timeout() | hibernate} |
                     {stop, term(), term()}.

handle_info(Info, State)

-spec handle_info(term(), term()) ->
                     {noreply, term()} |
                     {noreply, term(), timeout() | hibernate} |
                     {stop, term(), term()}.

info()

-spec info() ->
              {ok,
               #{atom() =>
                     #site_status{site :: atom(),
                                  is_enabled :: term(),
                                  status :: site_status(),
                                  pid :: undefined | pid(),
                                  start_time :: undefined | z_datetime:timestamp(),
                                  stop_time :: undefined | erlang:timestamp(),
                                  stop_count :: integer(),
                                  crash_time :: undefined | erlang:timestamp(),
                                  crash_count :: integer(),
                                  config :: list()}}}.

Return information on all running sites.

init(_)

-spec init(term()) -> {ok, term()} | {ok, term(), timeout() | hibernate} | ignore | {stop, term()}.

Initiates the server.

is_sites_running()

-spec is_sites_running() -> boolean().

Return true iff all sites are running. Don't count sites manually stopped.

module_loaded(Module)

Tell the sites manager that a module was loaded, check changes to observers, schema.

put_site_config_overrides(Site, Overrides)

-spec put_site_config_overrides(Site, Overrides) -> ok
                                   when Site :: atom(), Overrides :: proplists:proplist().

Override a given site config with arbitrary key/value pairs. Should be called before the site is started.

reload_site_config(Site)

-spec reload_site_config(atom()) -> ok | {error, bad_name | term()}.

Let the sites manager reload the configuration of a site.

restart(Site)

Restart a site or multiple sites.

set_site_status(Site, Status)

-spec set_site_status(atom(), site_status()) -> ok.

Set the status of a site, called by the site supervisor

start(Site)

Start a site or multiple sites.

start_link()

-spec start_link() -> {ok, pid()} | ignore | {error, term()}.

Starts the server

stop(Site)

Stop a site or multiple sites.

terminate(Reason, State)

-spec terminate(term(), term()) -> ok.

This function is called by a gen_server when it is about to terminate.

upgrade()

-spec upgrade() -> ok.

Sync the supervised sites with the sites in the sites directory. Removes and stops deleted sites, adds (but does not start) new sites.

wait_for_running(Site)

-spec wait_for_running(atom()) -> ok | {error, bad_name | timeout | stopped | removing | term()}.

Wait for a site to be running, max 30 secs.

wait_for_running(Site, Secs)

-spec wait_for_running(atom(), Secs :: integer()) ->
                          ok | {error, bad_name | timeout | stopped | removing | term()}.