Run a persistent process via ssh

后端 未结 5 454
北恋
北恋 2020-12-17 09:50

I\'m trying to start a test server via ssh but it always dies once i disconnect from ssh.

Is there a way to start a process (run the server) so it doesn\'t die upon

5条回答
  •  醉梦人生
    2020-12-17 10:28

    If you're SSHing to a Linux distro that has systemd, you can use systemd-run to launch a process in the background (in systemd's terms, "a transient service"). For example, assuming you want to ping something in the background:

    systemd-run --unit=pinger ping 10.8.178.3
    

    The benefit you'll get with systemd over just running a process with nohup is that systemd will track the process and its children, keep logs, remember the exit code and allow you to cleanly kill the process and all its children. Examples:

    See the status and the last lines of output:

    systemctl status pinger
    

    Stream the output:

    journalctl -xfu pinger
    

    Kill:

    systemctl kill pinger
    

提交回复
热议问题