3

This is my first attempt at running a Linux server. I have a server application which I want to run on a server to which I have ssh access.

If this were a Windows server, I'd just open a remote desktop, run the thing and disconnect the remote desktop session. However, it is my understanding that logging out of an ssh session kills all processes spawned within.

So I did a bit of searching and it seems I'll have to use screen or tmux to keep my process running after a disconnection. However, I'd like to know if there's a better way. The server process should be able to read control commands from stdin, and I'd rather be able to view some stdout logging output as well (though the rest of it inevitably goes into a log file).


UPDATE: I'm currently running the app inside a tmux session. It seems to be working alright, but I don't quite feel this is the best possible way...

  • could you please explain more? what kind of programming language you tried to deploy? – Moorthy GK Oct 13 '18 at 5:30
  • It's going to be a dotnet core application. It'll manage its own connections and open its own ports. – Arshia001 Oct 15 '18 at 7:22
  • .NET application will run on Nginx server. Please refer the following document to deploy .net application in Ubuntu server. docs.microsoft.com/en-us/aspnet/core/host-and-deploy/… – Moorthy GK Oct 17 '18 at 8:54
  • As I already mentioned, it's not an ASP.net app. – Arshia001 Oct 17 '18 at 15:12
1

To run a server in Linux you add it to the things that are run by systemd. Services are described by a short service file that is put in /etc/systemd/system/{target}/ where {target} indicates a system state (typically, multi-user.target.wants). The service description includes things like the executable to run, and what do to if it exits. For instance, a mysql server:

# MySQL systemd service file

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755

Once the file is set up, you use the systemctl command:

  • systemctl start {service} to start the server
  • systemctl stop {service} to stop the server
  • systemctl enable {service} to make the server start after a boot
  • systemctl disable {service} to prevent the sever from starting after a reboot
  • If I did that, would I be able to access the process' stdout and stdin, should the need arise? – Arshia001 Oct 21 '18 at 8:48
  • See this. But a real server does its own logging. – xenoid Oct 21 '18 at 10:02
  • Sure it does, but in development scenarios, you just can't beat stdout XD – Arshia001 Oct 21 '18 at 10:09
  • I beg to differ. All the code you put in for debug can later be used for logging in "Debug" mode... :) – xenoid Oct 21 '18 at 11:02
  • What's wrong with having an additional console logger in debug builds and looking at the output directly? Not to mention issuing simple commands via stdin. Otherwise, you'd need to open a network port and firewall it off, and then code a different tool to pass the commands to the server. – Arshia001 Oct 21 '18 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.