HTTP server stops when SSH session ends

34 views
Skip to first unread message

vladac...@gmail.com

unread,
Jun 2, 2014, 5:34:40 AM6/2/14
to swi-p...@googlegroups.com
Hi,

I am in the process of deploying an HTTP server written in SWI-Prolog. To do this, I am using SSH to access the Linux machine which will run the server. I am able to start SWI-Prolog on this machine and start my HTTP server, and everything seems to be working fine. However, as soon as I close the SSH session, all swipl processes are also closed.

I have so far tried the "classical" solution of disowning the swipl process (as described by the accepted answer in this thread http://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup). However, the server is not accessible when the swipl process is running in the background. I believe it is because the main swipl process is actually spawning a bunch of child processes to run the server, but these child processes are not active when the swipl process runs in the background (maybe I'm wrong).

Does anyone have any suggestions as to how I can make my server continue to run even after closing the SSH session? I guess even swi-prolog.org must have ran into the same issue at some point.

Cheers,
Vlad

Igor Wojnicki

unread,
Jun 2, 2014, 7:17:39 AM6/2/14
to vladac...@gmail.com, swi-p...@googlegroups.com
Vlad,

The way I often apply is to use screen:

- ssh to the server
- screen
- swipl ....
- ^a d

then you can log out. An added benefit is that you can login again and
reattach the screen session which will bring you toplevel of the swi
prolog instance you started.

to reattach:

- ssh to the server
- screen -d -r

enjoy :)

Cheers,
Igor.
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

vladac...@gmail.com

unread,
Jun 2, 2014, 8:13:59 AM6/2/14
to swi-p...@googlegroups.com, vladac...@gmail.com
Hi Igor,

Thank you for the suggestion. This approach looks very promising.

However, there is one aspect I don't understand in the workflow that you suggest. After typing swipl into the terminal console, the SWI-Prolog console is launched. Typing Ctrl+d at this point will just cause SWI-Prolog to halt, as opposed to the intended effect of detaching the screen. So the workflow you have suggested becomes something like:


- ssh to the server
- screen
- swipl
:- start_my_server().
:- ^a d % Prolog halts now
- back to the attached screen (typing "^a d" again will lead to the original terminal)

Is there any way to exit the Prolog console without stopping the swipl process? Or, alternatively, a way of executing a Prolog script and immediately returning to the terminal console without stopping Prolog?

Cheers,
Vlad

vladac...@gmail.com

unread,
Jun 2, 2014, 8:48:07 AM6/2/14
to swi-p...@googlegroups.com, vladac...@gmail.com
Hi Igor,

I eventually figured it out. I was using Ctrl+d when I should have been using Ctrl+a and then typing "d" to detach the current screen.

Your solution did the trick for me, thanks again.

Cheers,
Vlad
Reply all
Reply to author
Forward
0 new messages