~hristoast/hristoast

4308ba78bcfb79b2ee050f87233aedf00aa6a231 — Hristos N. Triantafillou 2 months ago 757582e
No links, they come from the toc plugin now

Prevent dark mode from looking terrible
1 files changed, 7 insertions(+), 7 deletions(-)

M site/emacs-daemon-runit-service.html
M site/emacs-daemon-runit-service.html => site/emacs-daemon-runit-service.html +7 -7
@@ 12,7 12,7 @@

<div id="toc"></div>

<h4 id="requirements"><a style="color: #222; text-decoration: none;" href="#requirements">Requirements</a></h4>
<h4>Requirements</h4>

<p>Before you get too excited, there's a few prerequisites you'll need for this to be possible:</p>



@@ 23,7 23,7 @@

I'll also go into detail about how to configure <code>sudo</code> as well as hotkeys for OpenBox.

<h4 id="the-service"><a style="color: #222; text-decoration: none;" href="#the-service">The Service</a></h4>
<h4>The Service</h4>

<p>The service "run" file is below:</p>



@@ 38,7 38,7 @@ exec chpst -u hristos:hristos /usr/bin/emacs --fg-daemon=hristos-emacsd 2>&1</co

<p>This is nicer than having to give the path to the server's socket; easier for a human to reason about.</p>

<h4 id="optional-logging"><a style="color: #222; text-decoration: none;" href="#optional-logging">Optional Logging</a></h4>
<h4>Optional Logging</h4>

<p>This is optional, but I prefer to add logging to all runit services.  Doing this is standard fare for a runit service; Create a direcory called "log" in the root of your "emacs-daemon" service directory, and within that put a file called "run" with the below contents:</p>



@@ 47,7 47,7 @@ exec logger -t emacs-daemon</code></pre>

<p>Make sure you have something like <code>rsyslog</code> installed, and then you'll be able to find your "emacs-daemon" service logs in <code>/var/log/syslog</code> or wherever your logs go.  You can of course look at this output in the <code>*Messages*</code> buffer, but what the hay am I right?</p>

<h4 id="run-it"><a style="color: #222; text-decoration: none;" href="#run-it">Run It</a></h4>
<h4>Run It</h4>

<p>Now's the time to enable the service so that it can be used:</p>



@@ 55,7 55,7 @@ exec logger -t emacs-daemon</code></pre>

<p>Alter the paths to match where your things actually are, and then that's it.  The Emacs daemon is now running.</p>

<h4 id="connecting"><a style="color: #222; text-decoration: none;" href="#connecting">Connecting</a></h4>
<h4>Connecting</h4>

<p>As I showed above, you can now connect with a simple invocation of <code>emacsclient</code>, but some aliases would be a lot better.  For fish, I use this function:</p>



@@ 78,7 78,7 @@ end</code></pre>

<p>Now you can open Emacs, and connect to your daemon with a simple press of "Meta+E"!</p>

<h4 id="sudo-rules"><a style="color: #222; text-decoration: none;" href="#sudo-rules">Sudo Rules</a></h4>
<h4>Sudo Rules</h4>

<p>Although it's actually simple to close the daemon from within Emacs itself, thus prompting runit to relaunch a new process, it's still great to be able to use <code>sv</code> to manage the service if need be.  Even better, you can use sudo rules to allow you to do this without needing a password.  Put the following in <code>/etc/sudoers.d/emacs-daemon</code>:</p>



@@ 87,6 87,6 @@ hristos ALL=(ALL) NOPASSWD: EMACSD_CMDS</code></pre>

<p>Of course replace user names and commands as needed, but that's all you need.</p>

<h4 id="conclusion"><a style="color: #222; text-decoration: none;" href="#conclusion">Conclusion</a></h4>
<h4>Conclusion</h4>

<p>For a long time I managed an Emacs daemon outside of runit (or any other service manager) and it was fine; One can run <code>emacsclient</code> with the <code>--alternative-editor=''</code> option and that will start the daemon if it's not already running.  But having it start with your system, and having simple system-level controls for it is pretty useful and worthwhile considering the small amounts of effort required to implement.</p>