2021-01-01 20:12:34 +01:00
|
|
|
#+TITLE: =systemd= services and timers
|
|
|
|
#+SETUPFILE: ./setup/org-setup-file.org
|
2020-01-11 22:04:28 +01:00
|
|
|
|
|
|
|
https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
|
2019-04-04 10:26:43 +02:00
|
|
|
|
2021-01-01 20:12:34 +01:00
|
|
|
* =braingit= - Automatic commit and push new brain pages
|
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/braingit.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Sync Brain Website everyday
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=yes
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=%h/.local/bin/brain_git_push
|
2021-01-01 20:12:34 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Timer
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/braingit.timer
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Sync Brain Website everyday
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=no
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
OnCalendar=*-*-* 16:00:00
|
|
|
|
Persistent=true
|
|
|
|
Unit=braingit.service
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
2021-01-01 20:12:34 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Script
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.local/bin/brain_git_push
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:header-args+: :shebang "#!/usr/bin/env bash"
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+begin_src bash
|
2022-05-09 10:03:08 +02:00
|
|
|
cd ~/Cloud/programming/brain-website/
|
2021-01-08 01:26:27 +01:00
|
|
|
|
|
|
|
if [[ ! -z $(git status -s content/) ]]
|
|
|
|
then
|
|
|
|
git add content static && \
|
|
|
|
git commit -m "Update Content - $(date +%F)" && \
|
|
|
|
git push
|
|
|
|
exit
|
|
|
|
fi
|
2021-01-01 20:12:34 +01:00
|
|
|
#+end_src
|
2022-05-09 10:03:08 +02:00
|
|
|
|
2021-01-01 20:12:34 +01:00
|
|
|
* =checkmail= - Check new mails
|
2019-04-04 10:26:43 +02:00
|
|
|
** Service
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/checkmail.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
2019-04-04 10:26:43 +02:00
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Check new mails
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=yes
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=%h/.local/bin/checkmail -q
|
2019-04-04 10:26:43 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Timer
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/checkmail.timer
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
2019-04-04 10:26:43 +02:00
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Check Mail every x minutes
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=no
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
Requires=checkmail.service
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
Persistent=false
|
|
|
|
OnBootSec=2min
|
|
|
|
OnUnitActiveSec=5min
|
|
|
|
AccuracySec=2min
|
|
|
|
Unit=checkmail.service
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
2019-04-04 10:26:43 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Script
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
2020-04-07 09:30:28 +02:00
|
|
|
:header-args: :tangle ~/.local/bin/checkmail
|
2019-12-16 08:53:36 +01:00
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:header-args+: :shebang "#!/usr/bin/env bash"
|
|
|
|
:END:
|
2019-04-04 10:26:43 +02:00
|
|
|
|
|
|
|
#+begin_src bash
|
2021-01-08 01:26:27 +01:00
|
|
|
while [ -n "$1" ]; do # while loop starts
|
|
|
|
case "$1" in
|
|
|
|
-a) opt_all='--all' ;; # Check All inboxes
|
|
|
|
-v) opt_verbose='--verbose' ;; # Verbose
|
|
|
|
-q) opt_quiet='--quiet' ;; # Quiet
|
|
|
|
,*) echo "Option $1 not recognized" ;; # In case you typed a different option
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Count number of mails
|
|
|
|
gmail_old="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
|
|
|
|
esrf_old="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
|
|
|
|
# =============================================================
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Retreive mails
|
2022-02-06 22:15:14 +01:00
|
|
|
mbsync $opt_all $opt_verbose gmail-Home esrf-Home 2>/tmp/mbsync.log
|
2021-01-08 01:26:27 +01:00
|
|
|
# =============================================================
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Count number of mails
|
|
|
|
gmail_new="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
|
|
|
|
esrf_new="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
|
|
|
|
# =============================================================
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Total Number of new mails since last checking
|
2022-02-06 22:15:14 +01:00
|
|
|
new="$(($esrf_new+$gmail_new))"
|
|
|
|
old="$(($esrf_old+$gmail_old))"
|
2021-01-08 01:26:27 +01:00
|
|
|
# =============================================================
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Notification
|
|
|
|
if [ "$new" -gt 0 ]; then
|
2022-02-06 21:45:41 +01:00
|
|
|
notify-send --hint=string:x-dunst-stack-tag:fV84ivMi 'Mails ' "$new new mail(s)"
|
2021-01-08 01:26:27 +01:00
|
|
|
fi
|
|
|
|
# =============================================================
|
|
|
|
|
|
|
|
# =============================================================
|
|
|
|
# Indexation and Tags
|
|
|
|
if pgrep -f 'mu server'; then
|
|
|
|
emacsclient --eval '(mu4e-update-index)'
|
|
|
|
else
|
2022-02-06 21:51:52 +01:00
|
|
|
mu index -m ~/.mail $opt_verbose $opt_quiet
|
2021-01-08 01:26:27 +01:00
|
|
|
fi
|
|
|
|
# =============================================================
|
2019-04-04 10:26:43 +02:00
|
|
|
#+end_src
|
|
|
|
|
2021-01-01 20:12:34 +01:00
|
|
|
* =syncmail= - Synchronize all mails
|
2019-04-04 10:26:43 +02:00
|
|
|
** Service
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/syncmail.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
2019-04-04 10:26:43 +02:00
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Sync all mails
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=yes
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=%h/.local/bin/checkmail -a -q
|
2019-04-04 10:26:43 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Timer
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/syncmail.timer
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
2019-04-04 10:26:43 +02:00
|
|
|
|
|
|
|
#+BEGIN_SRC conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Sync All Mails every x hours
|
|
|
|
RefuseManualStart=no
|
|
|
|
RefuseManualStop=no
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
Requires=syncmail.service
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
Persistent=false
|
|
|
|
OnBootSec=30min
|
|
|
|
OnUnitActiveSec=300min
|
|
|
|
AccuracySec=10min
|
|
|
|
Unit=syncmail.service
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
2019-04-04 10:26:43 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
2021-01-01 20:12:34 +01:00
|
|
|
* =vdirsyncer= - Synchronize calendar and contacts
|
2019-04-04 10:26:43 +02:00
|
|
|
** Service
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/vdirsyncer.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
2019-04-04 10:26:43 +02:00
|
|
|
#+begin_src conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Synchronize calendars and contacts
|
|
|
|
Documentation=https://vdirsyncer.readthedocs.org/
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
|
|
|
|
[Service]
|
2021-10-25 14:31:23 +02:00
|
|
|
ExecStart=/home/thomas/.local/bin/vdirsyncer --verbosity "ERROR" sync
|
2021-01-08 01:26:27 +01:00
|
|
|
Type=oneshot
|
2019-04-04 10:26:43 +02:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
** Timer
|
2019-12-16 08:53:36 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/vdirsyncer.timer
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
2019-04-04 10:26:43 +02:00
|
|
|
#+begin_src conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=Synchronize vdirs
|
2019-04-04 10:26:43 +02:00
|
|
|
|
2021-01-08 01:26:27 +01:00
|
|
|
[Timer]
|
|
|
|
OnBootSec=5m
|
|
|
|
OnUnitActiveSec=15m
|
|
|
|
AccuracySec=5m
|
2019-04-04 10:26:43 +02:00
|
|
|
|
2021-01-08 01:26:27 +01:00
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
2019-04-04 10:26:43 +02:00
|
|
|
#+end_src
|
2019-05-16 21:13:08 +02:00
|
|
|
|
2022-02-06 21:51:52 +01:00
|
|
|
* TODO =ssh-agent= - SSH Agent
|
2020-01-28 21:30:34 +01:00
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
2020-03-01 21:36:01 +01:00
|
|
|
:header-args: :tangle ~/.config/systemd/user/ssh-agent.service
|
2020-01-28 21:30:34 +01:00
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
2019-04-10 16:57:25 +02:00
|
|
|
#+begin_src conf
|
2021-01-08 01:26:27 +01:00
|
|
|
[Unit]
|
|
|
|
Description=SSH key agent
|
2019-05-02 10:44:57 +02:00
|
|
|
|
2021-01-08 01:26:27 +01:00
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
|
|
|
|
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
|
2019-05-02 10:44:57 +02:00
|
|
|
|
2021-01-08 01:26:27 +01:00
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
2019-05-02 10:44:57 +02:00
|
|
|
#+end_src
|
2019-06-22 17:19:38 +02:00
|
|
|
|
2022-02-06 21:51:52 +01:00
|
|
|
* TODO =emacs= - Emacs
|
2021-01-08 01:26:27 +01:00
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/emacs.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Emacs text editor
|
|
|
|
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
ExecStart=/usr/bin/emacs --fg-daemon
|
|
|
|
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
|
|
|
|
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
|
|
|
|
Restart=on-failure
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
#+end_src
|
2021-10-25 14:31:23 +02:00
|
|
|
|
2022-02-06 21:51:52 +01:00
|
|
|
* TODO =trash-empty= - Empty the trash for files older than 30 days
|
2021-10-25 14:31:23 +02:00
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/trash-empty.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Empty the trash for files older than 30 days
|
|
|
|
Documentation=https://github.com/andreafrancia/trash-cli
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=/home/thomas/.local/bin/trash-empty 30
|
|
|
|
Type=oneshot
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
** Timer
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/trash-empty.timer
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Empty trash
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
OnCalendar=*-*-* 16:00:00
|
|
|
|
Persistent=true
|
|
|
|
Unit=trash-empty
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
#+end_src
|
2022-02-06 21:48:51 +01:00
|
|
|
* =syncthing=
|
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/syncthing.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Syncthing - Open Source Continuous File Synchronization for %I
|
|
|
|
Documentation=man:syncthing(1)
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Environment="all_proxy=socks5://localhost:8080"
|
|
|
|
ExecStart=/usr/bin/syncthing -no-browser -gui-address="0.0.0.0:8384" -no-restart -logflags=0
|
|
|
|
Restart=on-failure
|
|
|
|
SuccessExitStatus=3 4
|
|
|
|
RestartForceExitStatus=3 4
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
* =homelab-tunnel= - SSH Tunnel
|
|
|
|
Useful to bypass firewalls.
|
|
|
|
This can we used on the browser:
|
|
|
|
- for =qutebrowser=, use =:set content.proxy socks5://localhost:8080= (can setup a shortcut for that)
|
|
|
|
|
|
|
|
This is also used for Syncthing.
|
|
|
|
|
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/homelab-tunnel.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Setup a secure tunnel with homelab
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -D 8080 -q -N -T homelab
|
|
|
|
|
|
|
|
# Restart every >2 seconds to avoid StartLimitInterval failure
|
|
|
|
RestartSec=5
|
|
|
|
Restart=always
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
#+end_src
|
2022-05-09 10:02:26 +02:00
|
|
|
|
|
|
|
* =esrf-tunnel= - SSH Tunnel
|
|
|
|
** Service
|
|
|
|
:PROPERTIES:
|
|
|
|
:header-args: :tangle ~/.config/systemd/user/esrf-tunnel.service
|
|
|
|
:header-args+: :comments both :mkdirp yes
|
|
|
|
:END:
|
|
|
|
|
|
|
|
#+begin_src conf
|
|
|
|
[Unit]
|
|
|
|
Description=Setup a secure tunnel with ESRF
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -D 8081 -q -N -T rnice.esrf.fr
|
|
|
|
|
|
|
|
# Restart every >2 seconds to avoid StartLimitInterval failure
|
|
|
|
RestartSec=5
|
|
|
|
Restart=always
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
#+end_src
|