literate-dotfiles/systemd.org

358 lines
8.2 KiB
Org Mode
Raw Normal View History

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
* =bukugit= - Automatic commit and push new bookmarks
2019-04-04 10:26:43 +02:00
** Service
2019-12-16 08:53:36 +01:00
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/bukugit.service
:header-args+: :comments both :mkdirp yes
:END:
2019-04-04 10:26:43 +02:00
#+BEGIN_SRC conf
[Unit]
Description=Sync Bookmarks every day
RefuseManualStart=no
RefuseManualStop=yes
[Service]
Type=oneshot
ExecStart=%h/.local/bin/buku_git_push
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/bukugit.timer
:header-args+: :comments both :mkdirp yes
:END:
2019-04-04 10:26:43 +02:00
#+BEGIN_SRC conf
[Unit]
Description=Sync All Mails every x hours
RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
After=network-online.target
2019-04-04 10:26:43 +02:00
[Timer]
OnCalendar=*-*-* 16:00:00
Persistent=true
Unit=bukugit.service
[Install]
WantedBy=default.target
#+END_SRC
** Script
2019-12-16 08:53:36 +01:00
:PROPERTIES:
:header-args: :tangle ~/.local/bin/buku_git_push
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
cd ~/.local/share/buku/
if [[ ! -z $(git status -s bookmarks.db) ]]
then
2020-11-03 11:32:38 +01:00
rm bookmarks.org;
buku -e bookmarks.org && \
cat header.org bookmarks.org > index.org && \
emacs index.org --batch -f org-html-export-to-html --kill && \
git add index.html
git add bookmarks.db && \
git commit -m "Changed bookmarks - $(date +%F)" && \
git push
2019-04-04 10:26:43 +02:00
exit
fi
#+end_src
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
[Unit]
Description=Sync Brain Website everyday
RefuseManualStart=no
RefuseManualStop=yes
[Service]
Type=oneshot
ExecStart=%h/.local/bin/brain_git_push
#+END_SRC
** Timer
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/braingit.timer
:header-args+: :comments both :mkdirp yes
:END:
#+BEGIN_SRC conf
[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
#+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
cd ~/Cloud/brain-website/
if [[ ! -z $(git status -s content/) ]]
then
git add content static && \
git commit -m "Update Content - $(date +%F)" && \
git push
exit
fi
#+end_src
* =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
[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
[Unit]
Description=Check Mail every x minutes
RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
After=network-online.target
2019-04-04 10:26:43 +02:00
Requires=checkmail.service
[Timer]
Persistent=false
OnBootSec=2min
OnUnitActiveSec=5min
AccuracySec=2min
2019-04-04 10:26:43 +02:00
Unit=checkmail.service
[Install]
WantedBy=default.target
#+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
2019-07-20 17:25:08 +02:00
while [ -n "$1" ]; do # while loop starts
case "$1" in
-a) opt_all='--all' ;; # Check All inboxes
2019-07-20 17:25:08 +02:00
-v) opt_verbose='--verbose' ;; # Verbose
-q) opt_quiet='--quiet' ;; # Quiet
,*) echo "Option $1 not recognized" ;; # In case you typed a different option
2019-07-20 17:25:08 +02:00
esac
shift
done
2019-04-04 10:26:43 +02:00
# =============================================================
# Count number of mails
gmail_old="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
esrf_old="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
ulg_old="$(ls ~/.mail/ulg/Inbox/new | wc -l)"
2020-01-28 21:27:48 +01:00
uliege_old="$(ls ~/.mail/uliege/Inbox/new | wc -l)"
2019-04-04 10:26:43 +02:00
# =============================================================
# =============================================================
# Retreive mails
mbsync $opt_all $opt_verbose gmail-Home esrf-Home ulg-Home uliege-Home 2>/tmp/mbsync.log
2019-04-04 10:26:43 +02:00
# =============================================================
# =============================================================
# Count number of mails
gmail_new="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
esrf_new="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
ulg_new="$(ls ~/.mail/ulg/Inbox/new | wc -l)"
2020-01-28 21:27:48 +01:00
uliege_new="$(ls ~/.mail/uliege/Inbox/new | wc -l)"
2019-04-04 10:26:43 +02:00
# =============================================================
# =============================================================
# Total Number of new mails since last checking
2020-01-28 21:27:48 +01:00
new="$(($gmail_new+$esrf_new+$ulg_new+$uliege_new))"
old="$(($gmail_old+$esrf_old+$ulg_old+$uliege_old))"
2019-04-04 10:26:43 +02:00
# =============================================================
# =============================================================
# Notification
if [ "$new" -gt 0 ]; then
2020-04-02 22:05:32 +02:00
dunstify --replace=98465 'Mails ' "$(($gmail_new+$esrf_new+$ulg_new+$uliege_new)) new mail(s)"
2019-04-04 10:26:43 +02:00
fi
# =============================================================
# =============================================================
# Indexation and Tags
if pgrep -f 'mu server'; then
emacsclient --eval '(mu4e-update-index)'
else
2020-05-26 08:36:28 +02:00
mu index $opt_verbose $opt_quiet
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
[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
[Unit]
Description=Sync All Mails every x hours
RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
After=network-online.target
2019-04-04 10:26:43 +02:00
Requires=syncmail.service
[Timer]
Persistent=false
OnBootSec=30min
OnUnitActiveSec=300min
AccuracySec=10min
2019-04-04 10:26:43 +02:00
Unit=syncmail.service
[Install]
WantedBy=default.target
#+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
[Unit]
Description=Synchronize calendars and contacts
Documentation=https://vdirsyncer.readthedocs.org/
Wants=network-online.target
After=network-online.target
2019-04-04 10:26:43 +02:00
[Service]
ExecStart=/usr/bin/vdirsyncer --verbosity "ERROR" sync
2019-04-04 10:26:43 +02:00
Type=oneshot
#+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
[Unit]
Description=Synchronize vdirs
[Timer]
OnBootSec=5m
OnUnitActiveSec=15m
AccuracySec=5m
[Install]
WantedBy=timers.target
#+end_src
2019-05-16 21:13:08 +02:00
2021-01-01 20:12:34 +01:00
* =ssh-agent= - SSH Agent
** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/ssh-agent.service
:header-args+: :comments both :mkdirp yes
:END:
2019-04-10 16:57:25 +02:00
#+begin_src conf
[Unit]
Description=SSH key agent
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
[Install]
WantedBy=default.target
#+end_src
2021-01-01 20:12:34 +01:00
* =powertop= - Powertop
** Service
2019-12-16 08:53:36 +01:00
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/powertop.service
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=Powertop tunings
[Service]
ExecStart=/usr/bin/powertop --auto-tune
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
#+end_src