Answers: <p>What you want can be done. I've seen it done with GNU screen when Tmux wasn't around yet. <em>However, I would not consider it good style to do it.</em></p>
  
  <p>There are better ways to do this. <a href="https://en.wikipedia.org/wiki/Daemon_(computing)#Unix-like_systems" rel="nofollow noreferrer">Daemons</a> are simply "normal" processes being run in a particular way. That particular way usually means to fork "twice" (so that the parent/child relationship gets broken) and plugging stdout, stdin and stderr to some file (or <code>/dev/null</code> if no logging is desired).</p>
  
  <p>There are tools aplenty out there to achieve what you want while also ensuring that there is a policy in place if the process unexpectedly goes down. After all a service should be available as close to 100% of the time as possible.</p>
  
  <p>Read up on:</p>
  
  <ul>
  <li><a href="https://en.wikipedia.org/wiki/Daemontools" rel="nofollow noreferrer">daemontools</a></li>
  <li><a href="http://supervisord.org/" rel="nofollow noreferrer">supervisor</a></li>
  <li><a href="https://linux.die.net/man/1/daemonize" rel="nofollow noreferrer">daemonize</a></li>
  <li><a href="http://smarden.org/runit/" rel="nofollow noreferrer">runit</a></li>
  </ul>
  
  <p>Arguably your system will already have one of these or a very similar tool installed. But you don't give enough information for me to provide more detail.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-26T06:55:21.643Z
Answers: 2020-05-26T06:55:21.643Z
Answers: 0xC0000022L
Body: <p>So I have some API server that I need to be up 24/7. Is it a bad idea to open up a tmux window and run the server application? When you run a binary in tmux, the binary stays running even when you close the tmux window. The binary also stays running when I disconnect from the SSH session. I like running the server application in tmux because I can easily just attach to the tmux window and have access to a shell where the executable lives. The server constantly prints log messages to standard output, meaning I like to be able to read those messages in my tmux window. However, there is something that just seems off about this method of running a server application. I would prefer if the server could somehow run in the background, but I also want to be able to see the logs that the terminal is printing out at any given time. So, to summarize, is it a bad idea to run a server application in tmux? If so, what do I do instead so that I can still read the server application's logs?</p>
  
Tags: <servers>
Title: Using tmux to host a server
UserDisplayName: Matt Y
ThreadText: # Using tmux to host a server
  
  (Asked by: username_0 on 2020-05-26)
  
  So I have some API server that I need to be up 24/7. Is it a bad idea to open up a tmux window and run the server application? When you run a binary in tmux, the binary stays running even when you close the tmux window. The binary also stays running when I disconnect from the SSH session. I like running the server application in tmux because I can easily just attach to the tmux window and have access to a shell where the executable lives. The server constantly prints log messages to standard output, meaning I like to be able to read those messages in my tmux window. However, there is something that just seems off about this method of running a server application. I would prefer if the server could somehow run in the background, but I also want to be able to see the logs that the terminal is printing out at any given time. So, to summarize, is it a bad idea to run a server application in tmux? If so, what do I do instead so that I can still read the server application's logs?
  
  **Tags:** servers
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-26. Score: 2
  
  What you want can be done. I've seen it done with GNU screen when Tmux wasn't around yet. *However, I would not consider it good style to do it.*
  
  There are better ways to do this. [Daemons](https://en.wikipedia.org/wiki/Daemon_(computing)#Unix-like_systems) are simply "normal" processes being run in a particular way. That particular way usually means to fork "twice" (so that the parent/child relationship gets broken) and plugging stdout, stdin and stderr to some file (or `/dev/null` if no logging is desired).
  
  There are tools aplenty out there to achieve what you want while also ensuring that there is a policy in place if the process unexpectedly goes down. After all a service should be available as close to 100% of the time as possible.
  
  Read up on:
  
  * [daemontools](https://en.wikipedia.org/wiki/Daemontools)
  * [supervisor](http://supervisord.org/)
  * [daemonize](https://linux.die.net/man/1/daemonize)
  * [runit](http://smarden.org/runit/)
  
  Arguably your system will already have one of these or a very similar tool installed. But you don't give enough information for me to provide more detail.
  
  
  ---
  
  