1

I followed the instructions

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files

create a emacs.service under /etc/systemd/system/like this

Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=forking
ExecStart=/home/hye/bin/emacs --fg-daemon
ExecStop=/home/hye/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=always

[Install]
WantedBy=default.target

then I execute:

systemctl daemon-reload
systemctl start emacs.service

the emacs.service launched successfully

However when I run emacsclient -t in terminal, it shows:

emacsclient: can't find socket; have you started the server?

I find that if I switch to root and run emacsclient -t in terminal, it works well.

In fact, host name is /tmp/emacs0/server, but I can't access it since it's owner is root.

emacsclient -t -s /tmp/emacs0/server
emacsclient: can't stat /tmp/emacs0/server: Permission denied
emacsclient: error accessing socket "/tmp/emacs0/server"

I have tried to add User option in emacs.service, like this

[Service]
User=hye
Group=hye
Type=forking

but systemctl can't start this service, it is always failed.

I have also tried to put emacs.service under ~/.config/systemd/user/

but centos 7 doesn't support systemctl --user.

system information:

Centos 7.6
Emacs-26.1 manually installed

Any advice would be appreciated!

Coco
  • 71
  • 1
  • 1
  • 8

1 Answers1

1

I had the same problem....

..it came down to I was using emacs-snapshot for emacs in

   update-alternatives --display emacs

..and a different version for emacsclient

Set it to the same version and then Good Things happened.

sudo update-alternatives --set emacsclient /usr/bin/emacsclient-snapshot
John Carter
  • 460
  • 3
  • 10
  • Thanks for your answer, right now I do not have a centos 7.6 system, I am using fedora 31, I can not testify your solution, anyway, thanks a lot – Coco Oct 22 '20 at 08:26
  • 1
    Yep! This right here. Somehow I have Emacs 25.3 in my /usr/local/bin, with its accompanying emacsclient. And that's the one found by `which`, while Emacs 27.1 is the version that's actually running on the computer. Choose the correct emacsclient, and voila! Back up and running. – lima Dec 22 '20 at 02:57