last day (15 days later) » 

23:12
0
Q: Setting Connection to "close" in Sinatra

VikatonI have this simple sinatra web app: require 'sinatra' get '/' do "Success." end get '/app' do "done" response["Connection"] = "Close" `sudo pkill blink` `gpio write 0 0` `sudo ./blink #{params["func"]}` end ./blink is a program that runs forever and does not termina...

It seems "done" shoud be placed at the end of the do ... end block after all other stuff, so the block should return this value. HTTP header Connection=close is far enough from what you need.
@andrykonchin I tried that and it doesn't show "done" until after I shut down the server, which shuts down the ./blink as well, so I still get the long loading loop
.Are you sure all your shell commands are completed fast and don't delay the response? Can you add some sort of logging to see all lines are executed or some lne are't execited?
@andrykonchin Like I said, the sudo ./blink #{params["func"]} line is executing a forever running program that does not complete/return
oh, sure, I got it. Have you tried to detach from the shell process with & command like sudo ./blink #{params["func"]} &?
23:12
@andrykonchin Just did, no such luck :(
Hm, can you check in terminal this command? Your shell comand have to release you terminal at least. Is it true (it releases) the issue is in another place.
andykonchin: Do you mean when I execute my command in terminal that it enables me to run another command right after? if so then no, the terminal is occupied by the forever running program
:27340750
> when I execute my command in terminal that it enables me to run another command right after?
yes
and "&" doesn't help, right?
Correct
This is why I thought using Connection: Close would solve this issue
can you provide shell commant you run in terminal?
23:20
the same as in the code: sudo ./blink 3
where 3 would be from the url parameters
have you tried in terminal command with "&" - "sudo ./blink 3 &"?
No, I will try now
ok so it gives me the id of the process and makes me able to write another command
but having that in my ruby code still gives me the long loop :(
can you run irb and execute the same code (but with &) which you run in web app?
`sudo ./blink #{params["func"]} &`
ok
doing that does not let me type any other ruby commands
so adding & in the ruby shell command wont work :(
hmmm, I see
I have only one idea - to create chell script, which will run your command and release the parent process like this:
#!/bin/bash
sudo ./blink $1 &
23:35
and from ruby, run sh run.sh #{params["func"]}
?
"sh run.sh #{params["func"]} "
ok will try now
there is another magic command "nohup"
it demonises your command, you can try to run
nohup ./blink $1 &
I might have to try that
because doing what u said about the sh file had the same outcome :(
I have no idea what else can help you, but you need to dive into Kernel#system coll, there are some parameters to fork processes, I thinki it can help you
write here your result with "nohup" please
23:45
ok
no such luck
only thing different is the nohup msg about stderr and stdout but still hangs
:'(

  last day (15 days later) »