mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-29 23:05:59 +08:00
Add LIVEBOOK_SHUTDOWN_ENABLED (#1111)
* Add LIVEBOOK_SHUTDOWN_ENABLED Previously we relied on code:get_mode(), but since releases are starting in interactive mode to use less memory, we need a clearer mechanism. * Move shutdown feature check to Livebook.Config Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
aa3b58d708
commit
5acbd2efad
8 changed files with 42 additions and 20 deletions
|
|
@ -180,6 +180,9 @@ The following environment variables configure Livebook:
|
||||||
long and it can be generated by commands such as: 'openssl rand -base64 48'.
|
long and it can be generated by commands such as: 'openssl rand -base64 48'.
|
||||||
Defaults to a random secret on every boot.
|
Defaults to a random secret on every boot.
|
||||||
|
|
||||||
|
* LIVEBOOK_SHUTDOWN_ENABLED - controls if a shutdown button should be shown
|
||||||
|
in the homepage. Set it to "true" to enable it.
|
||||||
|
|
||||||
* LIVEBOOK_TOKEN_ENABLED - controls whether token authentication is enabled.
|
* LIVEBOOK_TOKEN_ENABLED - controls whether token authentication is enabled.
|
||||||
Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
|
Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
|
||||||
disable it.
|
disable it.
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,12 @@ config :mime, :types, %{
|
||||||
"text/plain" => ["livemd"]
|
"text/plain" => ["livemd"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sets the default storage backend
|
config :livebook,
|
||||||
config :livebook, :storage, Livebook.Storage.Ets
|
authentication_mode: :token,
|
||||||
|
explore_notebooks: [],
|
||||||
# Sets the default authentication mode to token
|
plugs: [],
|
||||||
config :livebook, :authentication_mode, :token
|
shutdown_enabled: false,
|
||||||
|
storage: Livebook.Storage.Ets
|
||||||
config :livebook, :plugs, []
|
|
||||||
|
|
||||||
config :livebook, :explore_notebooks, []
|
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ config :livebook, LivebookWeb.Endpoint,
|
||||||
]
|
]
|
||||||
|
|
||||||
config :livebook, :iframe_port, 4001
|
config :livebook, :iframe_port, 4001
|
||||||
|
config :livebook, :shutdown_enabled, true
|
||||||
|
|
||||||
# ## SSL Support
|
# ## SSL Support
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ defmodule Livebook do
|
||||||
password = Livebook.Config.password!("LIVEBOOK_PASSWORD") ->
|
password = Livebook.Config.password!("LIVEBOOK_PASSWORD") ->
|
||||||
config :livebook, authentication_mode: :password, password: password
|
config :livebook, authentication_mode: :password, password: password
|
||||||
|
|
||||||
Livebook.Config.token_enabled!("LIVEBOOK_TOKEN_ENABLED") ->
|
Livebook.Config.boolean!("LIVEBOOK_TOKEN_ENABLED", true) ->
|
||||||
config :livebook, token: Livebook.Utils.random_id()
|
config :livebook, token: Livebook.Utils.random_id()
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
@ -113,6 +113,10 @@ defmodule Livebook do
|
||||||
config :livebook, :iframe_port, port
|
config :livebook, :iframe_port, port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Livebook.Config.boolean!("LIVEBOOK_SHUTDOWN_ENABLED", false) do
|
||||||
|
config :livebook, :shutdown_enabled, true
|
||||||
|
end
|
||||||
|
|
||||||
config :livebook,
|
config :livebook,
|
||||||
:default_runtime,
|
:default_runtime,
|
||||||
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,14 @@ defmodule Livebook.Config do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns whether the shutdown feature is enabled.
|
||||||
|
"""
|
||||||
|
@spec shutdown_enabled?() :: boolean()
|
||||||
|
def shutdown_enabled?() do
|
||||||
|
Application.fetch_env!(:livebook, :shutdown_enabled)
|
||||||
|
end
|
||||||
|
|
||||||
## Parsing
|
## Parsing
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -202,8 +210,11 @@ defmodule Livebook.Config do
|
||||||
@doc """
|
@doc """
|
||||||
Parses token auth setting from env.
|
Parses token auth setting from env.
|
||||||
"""
|
"""
|
||||||
def token_enabled!(env) do
|
def boolean!(env, default \\ false) do
|
||||||
System.get_env(env, "1") in ~w(true 1)
|
case System.get_env(env) do
|
||||||
|
nil -> default
|
||||||
|
var -> var in ~w(true 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ defmodule LivebookWeb.SidebarHelpers do
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown_item(assigns) do
|
def shutdown_item(assigns) do
|
||||||
if :code.get_mode() == :interactive do
|
if Livebook.Config.shutdown_enabled?() do
|
||||||
~H"""
|
~H"""
|
||||||
<span class="tooltip right distant" data-tooltip="Shutdown">
|
<span class="tooltip right distant" data-tooltip="Shutdown">
|
||||||
<button class="text-2xl text-gray-400 hover:text-gray-50 focus:text-gray-50 rounded-xl h-10 w-10 flex items-center justify-center"
|
<button class="text-2xl text-gray-400 hover:text-gray-50 focus:text-gray-50 rounded-xl h-10 w-10 flex items-center justify-center"
|
||||||
|
|
@ -121,13 +121,17 @@ defmodule LivebookWeb.SidebarHelpers do
|
||||||
end
|
end
|
||||||
|
|
||||||
def shared_home_handlers(socket) do
|
def shared_home_handlers(socket) do
|
||||||
attach_hook(socket, :shutdown, :handle_event, fn
|
if Livebook.Config.shutdown_enabled?() do
|
||||||
"shutdown", _params, socket ->
|
attach_hook(socket, :shutdown, :handle_event, fn
|
||||||
System.stop()
|
"shutdown", _params, socket ->
|
||||||
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
|
System.stop()
|
||||||
|
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
|
||||||
|
|
||||||
_event, _params, socket ->
|
_event, _params, socket ->
|
||||||
{:cont, socket}
|
{:cont, socket}
|
||||||
end)
|
end)
|
||||||
|
else
|
||||||
|
socket
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
set RELEASE_MODE=interactive
|
set RELEASE_MODE=interactive
|
||||||
|
set LIVEBOOK_SHUTDOWN_ENABLED=true
|
||||||
|
|
||||||
set cookie_path="!RELEASE_ROOT!\releases\COOKIE"
|
set cookie_path="!RELEASE_ROOT!\releases\COOKIE"
|
||||||
if not exist %cookie_path% (
|
if not exist %cookie_path% (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
export RELEASE_MODE=interactive
|
export RELEASE_MODE=interactive
|
||||||
|
export LIVEBOOK_SHUTDOWN_ENABLED=true
|
||||||
|
|
||||||
cookie_path="${RELEASE_ROOT}/releases/COOKIE"
|
cookie_path="${RELEASE_ROOT}/releases/COOKIE"
|
||||||
if [ ! -f $cookie_path ]; then
|
if [ ! -f $cookie_path ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue