From 8bbb33a77fe94180ae0cfccf756f5e4b35b31df4 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Tue, 6 Aug 2024 22:48:56 -0400 Subject: [PATCH] 0.7.1: Set proper permission to the UNIX socket --- config/config.yml | 2 +- src/file-uploader.cr | 25 ++++++++++--------------- src/jobs.cr | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/config/config.yml b/config/config.yml index b3735dc..faece0f 100644 --- a/config/config.yml +++ b/config/config.yml @@ -6,7 +6,7 @@ filename_length: 3 size_limit: 512 port: 8080 # If you define the unix socket, it will only listen on the socket and not the port. -#unix_socket: "/tmp/file-uploader.sock" +unix_socket: "/tmp/file-uploader.sock" # In days delete_files_after: 7 # In seconds diff --git a/src/file-uploader.cr b/src/file-uploader.cr index 60bcc69..b4bde23 100644 --- a/src/file-uploader.cr +++ b/src/file-uploader.cr @@ -31,23 +31,18 @@ Utils.create_db Utils.create_files_dir Routing.register_all -Jobs.run - Utils.delete_socket -# Simple but ugly way -if !CONFIG.unix_socket.nil? - Kemal.run do |config| - config.server.not_nil!.bind_unix "#{CONFIG.unix_socket}" - end -else - Kemal.run -end - -# Set permissions to 777 so NGINX can read and write to it (BROKEN) -sleep 1.second -LOGGER.info "Setting sock permissions to 777" -File.chmod("#{CONFIG.unix_socket}", File::Permissions::All) +Jobs.run {% if flag?(:release) || flag?(:production) %} Kemal.config.env = "production" if !ENV.has_key?("KEMAL_ENV") {% end %} + +# Set permissions to 777 so NGINX can read and write to it (BROKEN) +if !CONFIG.unix_socket.nil? + sleep 1.second + LOGGER.info "Setting sock permissions to 777" + File.chmod("#{CONFIG.unix_socket}", File::Permissions::All) +end + +sleep diff --git a/src/jobs.cr b/src/jobs.cr index 27949c1..617f85b 100644 --- a/src/jobs.cr +++ b/src/jobs.cr @@ -14,8 +14,22 @@ module Jobs return fiber end + def self.kemal + fiber = Fiber.new do + if !CONFIG.unix_socket.nil? + Kemal.run do |config| + config.server.not_nil!.bind_unix "#{CONFIG.unix_socket}" + end + else + Kemal.run + end + end + return fiber + end + def self.run # Tries to run the .enqueue method, if is not able to I will just not execute. check_old_files.try &.enqueue + kemal.try &.enqueue end end