1

I am facing with a well know problem, when I try to start emacs --daemon on a remote machine, I am getting following error emacsclient: connect: Connection refused:

$ ps aux | grep -E "[e]macs"  # returns empty
$ emacsclient -t -q doo.py
emacsclient: connect: Connection refused

Warning: due to a long standing Gtk+ bug
https://gitlab.gnome.org/GNOME/gtk/issues/221
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
## ...
Starting Emacs daemon.
Unable to start the daemon.
Another instance of Emacs is running the server, either as daemon or interactively.
You can use emacsclient to connect to that Emacs process.
Error: server did not start correctly
Error: Could not start the Emacs daemon


The way I connect into the remote machine ssh -Y4t user@IP zsh --login -i

I don't know what can I debug more to handle this or what is the issue. I also have same configuration on a different remote machine where it works without a problem.


Update based on @phils guide(please see in comments) debug in depth.
$ kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}')
$ ps aux | grep -E "[e]macs"  # returns empty
$ emacsclient -t -q doo.py
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".

Warning: due to a long standing Gtk+ bug
https://gitlab.gnome.org/GNOME/gtk/issues/221
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.

$ ps aux | grep -E "[e]macs"  # returns empty
netlab    9885 14.1  0.4 464628 67812 ?        Ssl  01:40   0:04 /snap/emacs/296/usr/bin/emacs --daemon
$ kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}')
$ ps aux | grep -E "[e]macs"  # returns empty

$ unset ALTERNATE_EDITOR
$ echo $ALTERNATE_EDITOR

$ ls -l /tmp/emacs1002/server
srwx------ 1 netlab netlab 0 Jul 16 01:40 /tmp/emacs1002/server
$ rm -rf /tmp/emacs1002/server
$ ls -l /tmp/emacs1002/server
ls: cannot access '/tmp/emacs1002/server': No such file or directory
$ emacsclient -t
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

    --socket-name
    --server-file      (or environment variable EMACS_SERVER_FILE)
    --alternate-editor (or environment variable ALTERNATE_EDITOR)
$ emacs -Q --daemon

Warning: due to a long standing Gtk+ bug
https://gitlab.gnome.org/GNOME/gtk/issues/221
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
Starting Emacs daemon.
$ ls -l /tmp/emacs1002/server
srwx------ 1 netlab netlab 0 Jul 16 01:42 /tmp/emacs1002/server
$  emacsclient -t
emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

    --socket-name
    --server-file      (or environment variable EMACS_SERVER_FILE)
    --alternate-editor (or environment variable ALTERNATE_EDITOR)
  • Perhaps there's an issue accessing the socket? What if you start emacs (non-server), and then M-x server-force-delete ? – phils Jul 15 at 20:32
  • It returns Connection file "/tmp/emacs1002/server" deleted. But when I start the daemon again I have face with the same error – alper Jul 15 at 20:34
  • I also realized having (xclip-mode 1) in the init file makes paste operation pretty slow but removing it also did not make any change – alper Jul 15 at 20:47
  • Check to see whether /tmp/emacs1002/server exists after running emacs --daemon. In fact, how are you starting the daemon? The session you've shown doesn't show that at all. – phils Jul 15 at 20:48
  • 1
    github.com/tealeg/emacs-snap/issues/1 would seem relevant, though. – phils Jul 15 at 23:12
0

Thanks to hands up here (https://github.com/tealeg/emacs-snap/issues/1#issuecomment-660462402) and @phils's help on comments

It seems the current snap is https://github.com/alexmurray/emacs-snap

I made a clean installation using Alex Murray's snap (emacs 26.3 from Alex Murray). I verify that emacs --daemon works perfectly fine.


The mistake I made;

When I was facing the error, I believe I I have used following ppa link :-( => sudo add-apt-repository ppa:kelleyk/emacs due to this documentation (https://linuxhint.com/ubuntu_emacs_installation/), which had the socket problem related to emacs --daemon issue I faced.


| improve this answer | |

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.