Page 1 of 1

Server Down when close console

PostPosted: Sun Nov 17, 2013 12:35
by Jenkings
Hello.

I have a little problem.

I have compiled and installed the minetest game / server on VPS.
I connect to VPS by SSH console and run server by typing ./minetestserver and the server starts,but problem is, when i close the SSH connection, the minetestserver stops :/

Can you help me please ?

PostPosted: Sun Nov 17, 2013 12:55
by sfan5
Use screen

PostPosted: Sun Nov 17, 2013 13:01
by Jenkings
There is nothing to screen :/

Simply when i close the SSH session, the server is down too, and the log file ends with standard message which is logged before it falls

PostPosted: Sun Nov 17, 2013 13:23
by sfan5
I mean this

PostPosted: Sun Nov 17, 2013 13:42
by Jenkings
Thanks a lot. It helped me ;)

PostPosted: Sun Nov 17, 2013 19:13
by BrandonReese
Or start it with ./minetestserver &

PostPosted: Sun Nov 17, 2013 19:37
by sfan5
BrandonReese wrote:Or start it with ./minetestserver &

It is way harder to kill one specific minetestserver instance when you do it like this.

PostPosted: Sun Nov 17, 2013 23:15
by lightonflux
Use tmux, it is so much better than screen! /flamewar_ends

tmux has some great features (screen might has - i never really used it)

Start tmux:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
tmux


"action key" in tmux:

ctrl+b

to list all "windows"

ctrl+b+l

get help: ctrl+b+?

go to "window" $number

ctrl+b+$number


i think you get the idea.

To logout of tmux like every where else:

ctrl+b+d

because ctrl+d will exit a shell

then tmux runs in the background, when you log in again just type
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
tmux a
(for append) and you will find your tmux session like it was before.

Also cool stuff: ctrl+b+" and ctrl+b+% you change between the sides with ctrl+b+arrow

PostPosted: Sun Nov 17, 2013 23:51
by lightonflux
I see nobody explained what happened. I try.

On UNIX/Linux processes are spawned in a tree.

At the root there is a process called "init" which is spawns every other process. init has the first PID (process ID) so 1 (or 0 on some systems).

So somewhere in the tree there is a process called sshd, which is the deamon (therefore the d in sshd) which provides the ssh server. When a user logs in via ssh sshd will spawn a process (ssh login shell) for the user. Now when the user starts a program like it will be spawned by the ssh login shell.

So minetest is a child of your ssh shell. When you exit the shell it will be exited (closed/terminated), therefore all childs (like the minecraft server) die.

Let's look at the simplified tree:

init
└─ sshd
└─ ssh session
└── login shell
└── minetest


So when you leave the session all three processes will die.

That's it.

There are several ways to "disconnect" a child process from its parent (it will get another parent - remember there is always init). Like

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
command &
command & disown
nohup command


When you use screen/tmux your process (minetest server) will be a child of screen/tmux, which is not a child of sshd or it's sessions for obvious reasons.

If you want to look at the tree, just use

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
pstree


Hope this explanation helps.

lightonflux

PostPosted: Mon Nov 18, 2013 20:45
by Jenkings
Thanks for all replies, I am a bit smarter now.

Now i understand this problem and know how it works ;)