From 769211e95616fecd6d81d5eabd14978f71b7c1c8 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 26 Jul 2016 15:19:32 +0200 Subject: [PATCH] Start Emacs daemon as a systemd service --- systemd/.config/systemd/user/emacs.service | 13 +++++++++++++ .../user/save-environment-variables@.service | 9 +++++++++ systemd/usr/bin/save-environment-variables | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 systemd/.config/systemd/user/emacs.service create mode 100644 systemd/.config/systemd/user/save-environment-variables@.service create mode 100755 systemd/usr/bin/save-environment-variables diff --git a/systemd/.config/systemd/user/emacs.service b/systemd/.config/systemd/user/emacs.service new file mode 100644 index 0000000..9d47b67 --- /dev/null +++ b/systemd/.config/systemd/user/emacs.service @@ -0,0 +1,13 @@ +[Unit] +Description=Emacs: the extensible, self-documenting text editor +After=save-environment-variables@emacs.service +Requires=save-environment-variables@emacs.service + +[Service] +Type=forking +ExecStart=/usr/bin/emacs --daemon +ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)" +Restart=always + +[Install] +WantedBy=default.target diff --git a/systemd/.config/systemd/user/save-environment-variables@.service b/systemd/.config/systemd/user/save-environment-variables@.service new file mode 100644 index 0000000..67a03a7 --- /dev/null +++ b/systemd/.config/systemd/user/save-environment-variables@.service @@ -0,0 +1,9 @@ +[Unit] +Description=Save specific environment variables + +[Service] +Type=oneshot +ExecStart=/home/chelys/usr/bin/save-environment-variables %h/.config/systemd/user/%i.service.d/env.conf PATH XDG_CONFIG_HOME XDG_DATA_HOME + +[Install] +WantedBy=default.target diff --git a/systemd/usr/bin/save-environment-variables b/systemd/usr/bin/save-environment-variables new file mode 100755 index 0000000..9735151 --- /dev/null +++ b/systemd/usr/bin/save-environment-variables @@ -0,0 +1,18 @@ +#!/usr/bin/env zsh + +output=$1 +shift + +source $HOME/.profile + +# Make sure the output directory exists. +[[ -d "$(dirname $output)" ]] || mkdir -p "$(dirname $output)" + +echo "[Service]" > "$output" + +# Write down all the environment variables. +for env in $@; do + echo "Environment=\"${env}=${(P)env}\"" +done >> "$output" + +systemctl --user daemon-reload