stack prosses

master
Izimic 2020-12-24 08:44:40 +01:00
parent 7332471fc5
commit 1d5750b770
1 changed files with 16 additions and 0 deletions

View File

@ -1,5 +1,7 @@
require "http/server" require "http/server"
require "option_parser" require "option_parser"
require "fiber"
require "./payload.cr" require "./payload.cr"
VERSION = 0.1 VERSION = 0.1
@ -57,6 +59,11 @@ if File.exists?(scriptfile_default) == false
exit 1 exit 1
end end
channel = Channel(Int32).new
spawn do
channel.send 0
end
server = HTTP::Server.new do |context| server = HTTP::Server.new do |context|
if context.request.method != "POST" || context.request.path != "/" if context.request.method != "POST" || context.request.path != "/"
context.response.status = HTTP::Status::NOT_FOUND context.response.status = HTTP::Status::NOT_FOUND
@ -82,7 +89,10 @@ server = HTTP::Server.new do |context|
scriptfile = path_project + "/../../../" + scriptfile_default scriptfile = path_project + "/../../../" + scriptfile_default
end end
channel.receive
File.write(path_jsonfile, payload.content) File.write(path_jsonfile, payload.content)
status = Process.run command: "zsh", args: [scriptfile], shell: true, status = Process.run command: "zsh", args: [scriptfile], shell: true,
error: STDERR, output: STDOUT, chdir: path_project error: STDERR, output: STDOUT, chdir: path_project
end end
@ -94,8 +104,14 @@ server = HTTP::Server.new do |context|
else else
context.response.print "FAILURE" context.response.print "FAILURE"
end end
spawn do
channel.send(0)
end
end end
end end
address = server.bind_tcp port address = server.bind_tcp port
pp address
server.listen server.listen