1

My current work workflow includes using PuTTY to SSH into a Linux development box with many users. I use an Emacs daemon to avoid the long startup times when closing my Emacs sessions. However, the Emacs daemon dies upon ending my SSH session. I was wondering if there is a way to spawn the daemon such that it persists beyond closing the SSH session? The only solution I have seen thus far is to use Emacs inside Tmux, however I much prefer the GUI Emacs.

  • You should be able to run the Emacs daemon in tmux or screen as well. – undercat Mar 6 at 3:03
  • You mean use the Emacs daemon in tmux but still use GUI Emacs? – Eric Hansen Mar 6 at 3:10
  • Sure. Either this, or nohup/disown. – undercat Mar 6 at 3:14
  • I have tried both nohup and disown unsuccessfully.. – Eric Hansen Mar 6 at 3:22
  • 1
    Any change, you're using Linux box with systemd-logind v230+, and you started emacs with emacs --daemon? You'll need to use systemd syntax to keep it running. – Danh Mar 6 at 3:57
2

Fleshing out the suggestion of @Danh to use systemd

Simple solution

Recent emacs has improved it's support for emacs as a service. This includes

  • the new fg-daemon option
  • an accompanying systemd service file

In your case you will also need to use lingering1 (lingering2) and the settings KillUserProcesses

Less simple

[You are using an earlier emacs that does not have fg-daemon]

In that case you must use type=forking. That requires also PIDFile=. AFAIK old Emacs doesn't provide this but here's a hack.

Allowing systemd to guess the pid works sometimes but is not recommended by systemd and should be treated as broken by default.

See also

  1. Debian bug
  2. Arch linux changes from default
  • It's not just systemd service units, either. Since 2016, there has been a service bundle, that normally goes in ~/.config/service-bundles/services/emacs, for running emacs 26 or later with --fg-daemon as a per-user service under the nosh toolset's per-user service management. – JdeBP Mar 6 at 7:57
  • @Erichansen Nice to see that you've accepted my suggestions. It would be good (for future readers) to see what combo of my suggestions worked for you. Updating your question with this would be best. Though just a comment "Followed no 2" or whatever also fine. – Rusi Mar 6 at 16:28

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.