0.7.1: Set proper permission to the UNIX socket

This commit is contained in:
Fijxu 2024-08-06 22:48:56 -04:00
parent 6f5e5c2007
commit 8bbb33a77f
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 25 additions and 16 deletions

View file

@ -6,7 +6,7 @@ filename_length: 3
size_limit: 512 size_limit: 512
port: 8080 port: 8080
# If you define the unix socket, it will only listen on the socket and not the port. # 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 # In days
delete_files_after: 7 delete_files_after: 7
# In seconds # In seconds

View file

@ -31,23 +31,18 @@ Utils.create_db
Utils.create_files_dir Utils.create_files_dir
Routing.register_all Routing.register_all
Jobs.run
Utils.delete_socket Utils.delete_socket
# Simple but ugly way Jobs.run
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)
{% if flag?(:release) || flag?(:production) %} {% if flag?(:release) || flag?(:production) %}
Kemal.config.env = "production" if !ENV.has_key?("KEMAL_ENV") Kemal.config.env = "production" if !ENV.has_key?("KEMAL_ENV")
{% end %} {% 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

View file

@ -14,8 +14,22 @@ module Jobs
return fiber return fiber
end 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 def self.run
# Tries to run the .enqueue method, if is not able to I will just not execute. # Tries to run the .enqueue method, if is not able to I will just not execute.
check_old_files.try &.enqueue check_old_files.try &.enqueue
kemal.try &.enqueue
end end
end end