From b4e930f3bcfa7996ac48e8fe288b5ab82e518aaa Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Fri, 13 Dec 2024 21:29:48 -0300 Subject: Change bind_unix to socket_binding, add socket_permissions and config example --- config/config.example.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/config.example.yml b/config/config.example.yml index a3a2eeb7..439063e1 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -130,6 +130,27 @@ https_only: false ## #hsts: true +## +## Path of a UNIX socket to listen on for incoming connections. +## +## Note: Enabling socket will make invidious stop listening on the address +## specified by 'host_binding' and 'port'. +## +## Accepted values: Any path to a new file (that doesn't exist yet) +## Default: +## +socket_binding: /tmp/invidious.sock + +## +## Permissions for the UNIX socket specified by 'socket_binding'. +## +## Note: The permissions are given in octal, following UNIX convention. +## +## Accepted values: 000-777 +## Default: 777 +## +socket_permissions: 777 + # ----------------------------- # Network (outbound) @@ -177,7 +198,7 @@ https_only: false ## Configuration for using a HTTP proxy ## ## If unset, then no HTTP proxy will be used. -## +## http_proxy: user: password: @@ -839,7 +860,7 @@ default_user_preferences: ## Default: true ## #vr_mode: true - + ## ## Save the playback position ## Allow to continue watching at the previous position when -- cgit v1.2.3 From 5f8130fd03a767f77bf8abe4a3f7260d2781850a Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Sat, 14 Dec 2024 05:39:03 -0300 Subject: Leave socket_binding disabled by default in the configuration example --- config/config.example.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/config.example.yml b/config/config.example.yml index 439063e1..3c090481 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -139,7 +139,7 @@ https_only: false ## Accepted values: Any path to a new file (that doesn't exist yet) ## Default: ## -socket_binding: /tmp/invidious.sock +#socket_binding: /tmp/invidious.sock ## ## Permissions for the UNIX socket specified by 'socket_binding'. @@ -149,7 +149,7 @@ socket_binding: /tmp/invidious.sock ## Accepted values: 000-777 ## Default: 777 ## -socket_permissions: 777 +#socket_permissions: 777 # ----------------------------- -- cgit v1.2.3 From 48d225002427e874a3b02ee0ba88ba6169304c52 Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Sat, 14 Dec 2024 06:53:30 -0300 Subject: Unify socket_binding and socket_permissions --- config/config.example.yml | 17 ++++------------- src/invidious.cr | 12 +++++++----- src/invidious/config.cr | 4 +--- 3 files changed, 12 insertions(+), 21 deletions(-) (limited to 'config') diff --git a/config/config.example.yml b/config/config.example.yml index 3c090481..afa1d252 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -131,25 +131,16 @@ https_only: false #hsts: true ## -## Path of a UNIX socket to listen on for incoming connections. +## Path and permissions of a UNIX socket to listen on for incoming connections. ## ## Note: Enabling socket will make invidious stop listening on the address ## specified by 'host_binding' and 'port'. ## -## Accepted values: Any path to a new file (that doesn't exist yet) +## Accepted values: Any path to a new file (that doesn't exist yet) and its +## permissions following the UNIX octal convention. ## Default: ## -#socket_binding: /tmp/invidious.sock - -## -## Permissions for the UNIX socket specified by 'socket_binding'. -## -## Note: The permissions are given in octal, following UNIX convention. -## -## Accepted values: 000-777 -## Default: 777 -## -#socket_permissions: 777 +#socket_binding: /tmp/invidious.sock,777 # ----------------------------- diff --git a/src/invidious.cr b/src/invidious.cr index 92ae8045..afbffcde 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -249,13 +249,15 @@ Kemal.config.app_name = "Invidious" Kemal.run do |config| if CONFIG.socket_binding - if File.exists?(CONFIG.socket_binding.not_nil!) - File.delete(CONFIG.socket_binding.not_nil!) + socket_binding = CONFIG.socket_binding.not_nil! + if File.exists?(socket_binding) + File.delete(socket_binding) end # Create a socket and set its desired permissions - server = UNIXServer.new(CONFIG.socket_binding.not_nil!) - perms = CONFIG.socket_permissions.to_i(base: 8) - File.chmod(CONFIG.socket_binding.not_nil!, perms) + tokens = socket_binding.rpartition(',') + server = UNIXServer.new(tokens[0]) + perms = tokens[2].to_i(base: 8) + File.chmod(tokens[0], perms) config.server.not_nil!.bind server else Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 7c9e9ca6..feda3958 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -138,10 +138,8 @@ class Config property port : Int32 = 3000 # Host to bind (overridden by command line argument) property host_binding : String = "0.0.0.0" - # Make Invidious listen on a UNIX socket instead of a TCP port - Example: /tmp/invidious.sock + # Path and permissions to make Invidious listen on a UNIX socket instead of a TCP port - Example: /tmp/invidious.sock,777 property socket_binding : String? = nil - # Permissions of the listening socket in octal - property socket_permissions : String = "777" # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`) property pool_size : Int32 = 100 # HTTP Proxy configuration -- cgit v1.2.3 From 275318dae2056737f101054b8e4527091fb0e73f Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Sat, 14 Dec 2024 15:18:25 -0300 Subject: Change socket_binding to a nested configuration in YAML --- config/config.example.yml | 4 +++- src/invidious.cr | 11 +++++------ src/invidious/config.cr | 9 ++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'config') diff --git a/config/config.example.yml b/config/config.example.yml index afa1d252..bb616328 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -140,7 +140,9 @@ https_only: false ## permissions following the UNIX octal convention. ## Default: ## -#socket_binding: /tmp/invidious.sock,777 +#socket_binding: +# path: /tmp/invidious.sock +# permissions: 777 # ----------------------------- diff --git a/src/invidious.cr b/src/invidious.cr index afbffcde..8b0ab911 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -250,14 +250,13 @@ Kemal.config.app_name = "Invidious" Kemal.run do |config| if CONFIG.socket_binding socket_binding = CONFIG.socket_binding.not_nil! - if File.exists?(socket_binding) - File.delete(socket_binding) + if File.exists?(socket_binding.path) + File.delete(socket_binding.path) end # Create a socket and set its desired permissions - tokens = socket_binding.rpartition(',') - server = UNIXServer.new(tokens[0]) - perms = tokens[2].to_i(base: 8) - File.chmod(tokens[0], perms) + server = UNIXServer.new(socket_binding.path) + perms = socket_binding.permissions.to_i(base: 8) + File.chmod(socket_binding.path, perms) config.server.not_nil!.bind server else Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding diff --git a/src/invidious/config.cr b/src/invidious/config.cr index feda3958..b15cf832 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -8,6 +8,13 @@ struct DBConfig property dbname : String end +struct SocketBindingConfig + include YAML::Serializable + + property path : String + property permissions : String +end + struct ConfigPreferences include YAML::Serializable @@ -139,7 +146,7 @@ class Config # Host to bind (overridden by command line argument) property host_binding : String = "0.0.0.0" # Path and permissions to make Invidious listen on a UNIX socket instead of a TCP port - Example: /tmp/invidious.sock,777 - property socket_binding : String? = nil + property socket_binding : SocketBindingConfig? = nil # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`) property pool_size : Int32 = 100 # HTTP Proxy configuration -- cgit v1.2.3 From f9885cca8e770fbbfec1c1360b71f19b344bb3fc Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Fri, 27 Dec 2024 15:09:05 -0300 Subject: Revert changes made to other parameters --- config/config.example.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/config.example.yml b/config/config.example.yml index bb616328..c5c3109d 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -191,7 +191,7 @@ https_only: false ## Configuration for using a HTTP proxy ## ## If unset, then no HTTP proxy will be used. -## +## http_proxy: user: password: @@ -853,7 +853,7 @@ default_user_preferences: ## Default: true ## #vr_mode: true - + ## ## Save the playback position ## Allow to continue watching at the previous position when -- cgit v1.2.3