0

Condider that I've built my application as in te example below:

library(RestRserve)
app = Application$new()
app$add_get(
  path = "/hello", 
  FUN = function(request, response) {
    response$set_body("Hello from RestRserve")
  })
backend = BackendRserve$new()
backend$start(app, http_port = 8080)

With the last command, Rserve wakes up and correctly listens and answers to the request on port 8080. Now, I would like to put the commands above in a script on a remote server, launch it with Rscript, and make it listen forever. However, once I disconnect from ssh, it stops working. Am I doing something wrong? Notice that I installed only RestRserve, Rserve come as a dependency, but I did not change anything or customized any configuration file.

Fabio
  • 518
  • 1
  • 4
  • 10

2 Answers2

2

Looking at the source code I'd suggest adding the named parameter background=TRUE to backend$start(app, http_port = 8080). This parameter is FALSE by default (line 36), when TRUE Rserve will be started in a new detached R-session (line 93). (Btw, leaving out said parameter you can check that the disconnect kills your running R-session by keeping a second SSH-connection open and listing running processes with a filter: ps aux | grep bin/exec/R before and after the disconnect)

If using said parameter works you might also want to look into server restarts. From the looks of it I'd say RestRserve cannot actually handle that by itself and you might need a small service script.

karo
  • 56
  • 4
  • thanks for your explanation. I addded ```background = TRUE```. However it does not work. The pid of application is 449147, but when i check with ```ps aux | grep R``` the porcess does not exists. Could that be something realted to RServe? I just intalled it as a dependencies of RestRserve, without configuring it – Fabio Jul 31 '20 at 07:48
  • Didn't have immediate access to a sufficiently recent Linux/R to test it myself, glad you could sort it out. – karo Jul 31 '20 at 12:29
1

I solved with the help of rexy.ai and karo: The correct script uses backend$start(app, http_port = 8080) (with no background option) but the deployment is made using nohup Rscript app.R &. This let the app run remotely and accept requests!

Fabio
  • 518
  • 1
  • 4
  • 10