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