Last Updated: March 19, 2021
·
4.788K
· nat-n

Use tmux for a poor man's daemon

If you have a service or process that you want to run in the background like a daemon that you can kill, restart of check that status of but otherwise stays detached, one quick and dirty solution is to create a tmux session around it.

For example the following one liner will create a new tmux session, identifiable as myServiceName, and inject into it the command string at the end (to launch the service inside the session).

tmux new-session -d -s myServiceName 'myServiceExecutable'

To have the process owned by another user prefix the command and the internal command string with sudo like so:

sudo tmux new-session -d -s myServiceName 'sudo -u someuser myServiceExecutable'

Check on or interact with the process via tmux attach -t myServiceName (prefixed by sudo if the session creation was), then to detach from the tmux session again type ctrl + b then d.

You can even have the service start on boot by adding the line to /etc/rc.local