💾 Archived View for chirale.org › 2019-05-15_5570.gmi captured on 2024-07-08 at 23:37:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-12)

-=-=-=-=-=-=-

Sort of CDN to serve client-side libraries via an auto-pull git repo on tmpfs

This configuration will allow to install on a Debian-based system a fast server for client libraries. Key technologies used are:

On this first step you’ll create a service to reserve some RAM for static files, pulling them from a private or public repo.

Mount tmpfs with systemd

To serve files directly from RAM, you have to mount a tmpfs directory. You can do it on fstab:

/etc/fstab

 tmpfs /mnt/cdn tmpfs rw,nodev,nosuid,size=300M 0 0 

Or with a systemd unit:

/etc/systemd/system/mnt-cdn.mount

 [Unit] Description=Mount empty CDN directory on volatile memory [Mount] What=tmpfs Where=/mnt/cdn Type=tmpfs Options=defaults,noatime,size=300M [Install] WantedBy=multi-user.target 

Create two units on a local path like /usr/local/share/systemd then create a symlinks on /etc/systemd/system or create directly them on /etc/systemd/system. You can also directly create them on /usr/local/share/systemd.

Create the pull service

When the /mnt/cdn is successfully loaded, pull static files from your repository.

/etc/systemd/system/cdn-pull.service

 [Unit] Description=Pull on CDN directory. After=network-online.target [Service] User=youruserhere Group=youruserhere ExecStart=/usr/local/share/systemd/cdn-pull.sh [Install] WantedBy=mnt-cdn.mount 

Meaning:

On pull, all files will be written by root as youruserhere:youruserhere.

After the pull, to reduce RAM occupation, this script doesn’t download directly to RAM .git directory but copy them with rsync excluding them:

/usr/local/share/systemd/cdn-pull.sh

 #!/bin/bash # stop on first error set -e cd /srv/cdn-all git pull exec rsync -a --exclude=.git --exclude=.gitignore /srv/cdn-all/* /mnt/cdn/ 

Get systemd to know about the mount and service

To reload systemd units, you have to

 systemctl daemon-reload 

Then do the mount via the systemd unit:

 systemctl start mnt-cdn.mount 

Enable on boot

Since the cdn-pull.service is tied to mnt-cdn.mount, both have to be enabled to run:

 systemctl enable mnt-cdn.mount systemctl enable cdn-pull.service 

When the system is ready create the tmpfs on /mnt/cdn/ After tmpfs is successfully created by the unit, the file will be automatically synced through cdn-pull.service.

Mount will auto-start sync

Start only the mnt-cdn.mount:

 systemctl start mnt-cdn.mount 

And then ask for info about both services:

 systemctl status mnt-cdn.mount systemctl status cdn-pull.service 

With this set-up, when you restart the mnt-cdn.mount files will be automatically pulled and synced to RAM when system starts and when you start or restart mnt-cdn.mount service.

Next you can serve these files on nginx and the final step could be to auto-detect push to update files automagically.

See also

https://web.archive.org/web/20190515000000*/https://en.wikipedia.org/wiki/Runlevel

https://web.archive.org/web/20190515000000*/https://chirale.org/2019/04/20/using-multiple-deploy-keys-on-github-using-ssh-config/

https://web.archive.org/web/20190515000000*/https://oguya.ch/posts/2015-09-01-systemd-mount-partition/