Skip to content

Latest commit

 

History

History
163 lines (152 loc) · 4.5 KB

background.org

File metadata and controls

163 lines (152 loc) · 4.5 KB

Background processes

Setup

Enable all the background services with:

systemctl --user enable --now haris-background.target

Systemd target for all background services

Note: Clipmenud is started by startx to ensure a graphical session exists.

[Unit]
Description=Background services
Wants=crontab-listen-update.service
Wants=emacs.service
Wants=irc.service
Wants=verm.service
Wants=ssh-agent.service
Wants=vpn-notifier.service
# Wants=clipmenud.service
AllowIsolate=yes

[Install]
WantedBy=default.target

Clipmenud

NOTE: The CM_DIR environment variable was overridden here.

[Unit]
Description=Clipboard daemon

[Service]
Environment=CM_DEBUG=1
Environment=CM_MAX_CLIPS=99999
Environment=XDG_RUNTIME_DIR=/run/user/%U
ExecStart=/usr/bin/env clipmenud

[Install]
WantedBy=default.target

Jira Branch Transformer

[Unit]
Description=Jira Branch Transformer

[Service]
ExecStart=/usr/bin/env jira-branch-transformer

[Install]
WantedBy=default.target

Executable

while :; do
    echo "Scanning clipboard..."
    cb="$(timeout 1s xsel -bo)"
    if grep -qE <<<"$cb" "^git checkout -b [A-Z]+-[0-9]+"; then
        echo "Clipboard matched. Transforming to branch name..."
        get-branch
    fi
    sleep 2
done

VPN Notifier

[Unit]
Description=VPN notifier

[Service]
Environment=XDG_RUNTIME_DIR=/run/user/%U
ExecStart=/usr/bin/env vpn-notifier
SyslogIdentifier=vpn-notifier

[Install]
WantedBy=default.target

Cron

I define my main users cron jobs in files matching the glob ~/.haris/cron.d/crontab.*.

Default cron jobs

:header-args+: :tangle (haris/tangle-home “.haris/cron.d/crontab.50”)Modify PATH variable to match the normal environment’s value:
PATH=<<eval-path-env()>>

Low battery suspend

* * * * * handle-low-bat

Check website online

0 */2 *   * 1-6 website-healthcheck
0 20  */4 * 1-6 website-healthcheck --notify-success

Remind me to reissue SSL certificate

0 18-23 10 */2 * notify-send 'REMINDER' 'Reissue SSL certificate for veracioux.me'

Update fish completions

0 20 * * * fish -c 'fish_update_completions'

Listen/update service

This service updates the user’s crontab when any of the custom crontab files change.

[Unit]
Description=Crontab change listener and updater

[Service]
ExecStart=<<eval-user-home()>>.local/bin/crontab-listen-update
Restart=on-failure

[Install]
WantedBy=default.target

Executable

if ! which inotifywait 2>/dev/null; then
    echo "ERROR: inotifywait is not installed. Aborting."
    exit 1
fi

mkdir -p ~/.haris/cron.d/
while :; do
    content=''
    for file in ~/.haris/cron.d/*; do
        echo "Read crontab file: $file"
        content="$(
            echo "$content"
            echo
            echo "############## START $file"
            echo
            cat "$file"
            echo
            echo "############## END  $file"
        )"
    done
    echo "$content" | crontab -
    echo "Resulting content of crontab:"
    crontab -l
    echo
    inotifywait -e modify -e attrib -e create -e delete ~/.haris/cron.d/
done

Helpers

(getenv "HOME")
(getenv "PATH")
(getenv "XDG_RUNTIME_DIR")

Local variables