-
Notifications
You must be signed in to change notification settings - Fork 0
Systemd service
Kovács József Miklós edited this page Aug 1, 2024
·
7 revisions
/home/user/ytcw/
├── channels.yaml
├── deploy.sh
├── dist-original
│ ├── <generated html, css etc. files>
├── ytcw.service
├── ytcw.sqlite3
├── ytcw.timer
└── ytcw-website (git repository)
└── dist
├── < minified html, css etc. files>
ytcw.timer
file:
[Unit]
Description=Run ytcw every 3 hours
Requires=ytcw.service
[Timer]
Unit=ytcw.service
OnCalendar=*-*-* 00,03,06,09,12,15,18,21:00:00
Persistent=true
[Install]
WantedBy=timers.target
ytcw.service
file:
[Unit]
Description=ytcw autoupdate
After=network.target
Wants=ytcw.timer
Requires=network-online.target
[Service]
Restart=no
Type=oneshot
WorkingDirectory=/home/user/ytcw/
ExecStart=/home/user/.local/bin/ytcw ytcw.sqlite3 channels.yaml -o dist-original/
ExecStartPost=/home/user/ytcw/deploy.sh
Environment="PATH=/home/user/.local/bin:/usr/bin:/bin"
User=user
Group=user
[Install]
WantedBy=multi-user.target
Using minify to minify the files.
deploy.sh
file:
#!/usr/bin/env bash
run_id=$(openssl rand -hex 4)
echo "run_id=${run_id}"
rm -rf ytcw-website/dist/
minify \
--recursive \
--output ytcw-website/dist/ \
--html-keep-comments \
--html-keep-conditional-comments \
--html-keep-default-attrvals \
--html-keep-document-tags \
--html-keep-end-tags \
--html-keep-quotes \
--html-keep-whitespace \
dist-original/
# Omitted in this example
cp robots.txt ytcw-website/dist/
cp dist-original/_headers ytcw-website/dist/
cd ytcw-website/ || exit 1
git add .
git commit -a -S -m "${run_id}"
git push
Setup, create a new GitHub/GitLab repository, configure SSH keys etc. Connect your preferred static site host to your git repository and configure it to deploy the dist/ directory ("build output directory").
Example SSH config
file (please read the docs):
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_gitlab
sudo cp ytcw.timer /etc/systemd/system/
sudo cp ytcw.service /etc/systemd/system/
sudo systemctl daemon-reload
Test it with:
sudo systemctl enable --now ytcw.timer
Status/output:
systemctl status ytcw.service
or follow it:
journalctl -u ytcw.service -f