mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-11 07:24:30 +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'.
|
||||
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.
|
||||
Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
|
||||
disable it.
|
||||
|
|
|
@ -19,15 +19,12 @@ config :mime, :types, %{
|
|||
"text/plain" => ["livemd"]
|
||||
}
|
||||
|
||||
# Sets the default storage backend
|
||||
config :livebook, :storage, Livebook.Storage.Ets
|
||||
|
||||
# Sets the default authentication mode to token
|
||||
config :livebook, :authentication_mode, :token
|
||||
|
||||
config :livebook, :plugs, []
|
||||
|
||||
config :livebook, :explore_notebooks, []
|
||||
config :livebook,
|
||||
authentication_mode: :token,
|
||||
explore_notebooks: [],
|
||||
plugs: [],
|
||||
shutdown_enabled: false,
|
||||
storage: Livebook.Storage.Ets
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# 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, :shutdown_enabled, true
|
||||
|
||||
# ## SSL Support
|
||||
#
|
||||
|
|
|
@ -102,7 +102,7 @@ defmodule Livebook do
|
|||
password = Livebook.Config.password!("LIVEBOOK_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()
|
||||
|
||||
true ->
|
||||
|
@ -113,6 +113,10 @@ defmodule Livebook do
|
|||
config :livebook, :iframe_port, port
|
||||
end
|
||||
|
||||
if Livebook.Config.boolean!("LIVEBOOK_SHUTDOWN_ENABLED", false) do
|
||||
config :livebook, :shutdown_enabled, true
|
||||
end
|
||||
|
||||
config :livebook,
|
||||
:default_runtime,
|
||||
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
||||
|
|
|
@ -98,6 +98,14 @@ defmodule Livebook.Config do
|
|||
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
|
||||
|
||||
@doc """
|
||||
|
@ -202,8 +210,11 @@ defmodule Livebook.Config do
|
|||
@doc """
|
||||
Parses token auth setting from env.
|
||||
"""
|
||||
def token_enabled!(env) do
|
||||
System.get_env(env, "1") in ~w(true 1)
|
||||
def boolean!(env, default \\ false) do
|
||||
case System.get_env(env) do
|
||||
nil -> default
|
||||
var -> var in ~w(true 1)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -58,7 +58,7 @@ defmodule LivebookWeb.SidebarHelpers do
|
|||
end
|
||||
|
||||
def shutdown_item(assigns) do
|
||||
if :code.get_mode() == :interactive do
|
||||
if Livebook.Config.shutdown_enabled?() do
|
||||
~H"""
|
||||
<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"
|
||||
|
@ -121,13 +121,17 @@ defmodule LivebookWeb.SidebarHelpers do
|
|||
end
|
||||
|
||||
def shared_home_handlers(socket) do
|
||||
attach_hook(socket, :shutdown, :handle_event, fn
|
||||
"shutdown", _params, socket ->
|
||||
System.stop()
|
||||
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
|
||||
if Livebook.Config.shutdown_enabled?() do
|
||||
attach_hook(socket, :shutdown, :handle_event, fn
|
||||
"shutdown", _params, socket ->
|
||||
System.stop()
|
||||
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
|
||||
|
||||
_event, _params, socket ->
|
||||
{:cont, socket}
|
||||
end)
|
||||
_event, _params, socket ->
|
||||
{:cont, socket}
|
||||
end)
|
||||
else
|
||||
socket
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
set RELEASE_MODE=interactive
|
||||
set LIVEBOOK_SHUTDOWN_ENABLED=true
|
||||
|
||||
set cookie_path="!RELEASE_ROOT!\releases\COOKIE"
|
||||
if not exist %cookie_path% (
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export RELEASE_MODE=interactive
|
||||
export LIVEBOOK_SHUTDOWN_ENABLED=true
|
||||
|
||||
cookie_path="${RELEASE_ROOT}/releases/COOKIE"
|
||||
if [ ! -f $cookie_path ]; then
|
||||
|
|
Loading…
Add table
Reference in a new issue