Module z_sites_manager

Server managing all sites running inside Zotonic.

Copyright © 2009-2020 Marc Worrell

Behaviours: gen_server.

Authors: Marc Worrell (marc@worrell.nl).

Description

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.

Data Types

site_status()

site_status() = new | starting | running | stopping | retrying | failed | stopped | removing

Function Index

await_startup/1Wait for a site to complete its startup sequence.
code_change/3Convert process state when code is changed.
do_scan_sites/0Scan all sites subdirectories for the site configurations.
do_scan_sites/1
filechanged_observer/1Called by the zotonic_filehandler after a file has been changed.
foreach/1Do something for all sites that are currently running.
get_builtin_sites/0The list of builtin sites, they are located in the zotonic/apps/ directory.
get_fallback_site/0Return the name of the site to handle unknown Host requests.
get_site_config/1Fetch the configuration of a specific site.
get_site_config_overrides/1
get_site_contexts/0Return a list of contexts for all running sites.
get_site_status/1Get the status of a particular site.
get_sites/0Return a list of all sites and their current running status.
get_sites_hosts/0Return a list of all sites, their current running status and their hosts configs.
handle_call/3Return all sites.
handle_cast/2
handle_info/2
info/0Return information on all running sites.
init/1Initiates the server.
is_sites_running/0Return true iff all sites are running.
module_loaded/1Tell the sites manager that a module was loaded, check changes to observers, schema.
put_site_config_overrides/2Override a given site config with arbitrary key/value pairs.
restart/1Restart a site or multiple sites.
set_site_status/2Set the status of a site, called by the site supervisor.
start/1Start a site or multiple sites.
start_link/0Starts the server.
stop/1Stop a site or multiple sites.
terminate/2This function is called by a gen_server when it is about to terminate.
upgrade/0Sync the supervised sites with the sites in the sites directory.
wait_for_running/1Wait for a site to be running, max 30 secs.
wait_for_running/2

Function Details

await_startup/1

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

Wait for a site to complete its startup sequence.

code_change/3

code_change(OldVsn, State, Extra) -> {ok, NewState}

Convert process state when code is changed

do_scan_sites/0

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

Scan all sites subdirectories for the site configurations.

do_scan_sites/1

do_scan_sites(X1) -> any()

filechanged_observer/1

filechanged_observer(Zotonic_filehandler_filechange::#zotonic_filehandler_filechange{}) -> 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/1

foreach(Fun::fun((z:context()) -> any())) -> ok

Do something for all sites that are currently running.

get_builtin_sites/0

get_builtin_sites() -> [atom()]

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

get_fallback_site/0

get_fallback_site() -> atom() | undefined

Return the name of the site to handle unknown Host requests

get_site_config/1

get_site_config(Site::atom()) -> {ok, list()} | {error, bad_name | term()}

Fetch the configuration of a specific site.

get_site_config_overrides/1

get_site_config_overrides(Site) -> any()

get_site_contexts/0

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

Return a list of contexts for all running sites.

get_site_status/1

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

Get the status of a particular site

get_sites/0

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/0

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/3

handle_call(Message::Request, From, State) -> {reply, Reply, State} | {reply, Reply, State, Timeout} | {noreply, State} | {noreply, State, Timeout} | {stop, Reason, Reply, State} | {stop, Reason, State}

Return all sites

handle_cast/2

handle_cast(Message::Msg, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

handle_info/2

handle_info(Info, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

info/0

info() -> {ok, #{atom() => #site_status{site = atom(), is_enabled = any(), status = site_status(), pid = undefined | pid(), mref = undefined | reference(), start_time = undefined | erlang:timestam(), 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/1

init(X1::Args) -> {ok, State} | {ok, State, Timeout} | ignore | {stop, Reason}

Initiates the server.

is_sites_running/0

is_sites_running() -> boolean()

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

module_loaded/1

module_loaded(Module) -> any()

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

put_site_config_overrides/2

put_site_config_overrides(Site, Overrides) -> any()

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

restart/1

restart(Site) -> any()

Restart a site or multiple sites.

set_site_status/2

set_site_status(Site::atom(), Status::site_status()) -> ok

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

start/1

start(Site) -> any()

Start a site or multiple sites.

start_link/0

start_link() -> {ok, Pid} | ignore | {error, Error}

Starts the server

stop/1

stop(Site) -> any()

Stop a site or multiple sites.

terminate/2

terminate(Reason, State) -> void()

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

upgrade/0

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/1

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

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

wait_for_running/2

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


Generated by EDoc