📜 ⬆️ ⬇️

We get ramlog on distributions with systemd

From the series "notes on the fields." More so as not to forget myself, but maybe someone will come in handy.

After purchasing the Raspberry Pi 2 to replace the one who did not live and the Odroid XU4 week, slow shamanism began to install and initialize the system for themselves. What a disappointment it was when the beloved ramlog refused not only to be installed (by hand, we would unpack, not lazy) , but also to be launched after the forced “implementation”. Desperate and requesting Google, I found out that it is not friendly with systemd, from the word “absolutely”.

Already practically gathering to fence something of his own , I came across one German post where the “adapted” ramlog was mentioned. The gutting of the immediately downloaded image showed that what I wanted was done there. Therefore, instead of inventing my bicycle, I suggest using the already prepared .
')

How does it work


Both the old and the new ramlog versions work on the same principle: download / var / log to memory when booting and write it to disk on command or shutdown.

The difference in the new version is in using the systemd launch mechanism and storing the logs in the archive, which radically simplified the code at the cost of archiving and unchanged files. Well, instead of running your own RAM disk, tmpfs is used, which, in which case, goes into a swap (and we have it on the zram and there is a great chance that there will be no disk access)

Installation


  1. Create a ramlog-a service (/ usr / bin / ramlog):
    / usr / bin / ramlog
    #!/bin/sh . /lib/lsb/init-functions start() { log_begin_msg "RAMLOG: Read files from disk.." tar xfz /var/ram_log.tar.gz -C / log_end_msg 0 } stop() { log_begin_msg "RAMLOG: Write files to disk.." tar cfz /var/ram_log.tar.gz --directory=/ var/log/ log_end_msg 0 } case "$1" in start) start ;; stop) stop ;; flush) stop ;; *) echo "Usage: $0 {start|stop|flush}" exit 1 esac 


  2. Create an entry for systemd (/etc/systemd/system/ramlog.service):
    Hidden text
     [Unit] Description=Ramlog After=local-fs.target Before=cron.service syslog.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/ramlog start ExecStop=/usr/bin/ramlog stop [Install] WantedBy=multi-user.target 

  3. Add an entry to CRON to periodically save logs:
     # ... #  15 ,    */15 * * * * /usr/bin/crontab flush >/dev/null 2>&1 

  4. Edit / etc / fstab, transferring / var / log to tmpfs:
     tmpfs /var/log tmpfs nodev,nosuid 0 0 

  5. Install the service:
     # insserv # systemctl enable ramlog.service 

  6. We start service
     # systemctl start ramlog.service 

    Now, on the next reboot, the contents of / var / log will be saved in /var/var_log.tar.gz, and loaded in tmpfs
  7. ... Profit!


Finishing touch Wishlist


It is quite possible to alter the logic of work by analogy with the original ramlog - you only need to do rsync instead of packaging to save. What is "more profitable" when working with flash drives - who knows?

The idea of ​​compressed tmpfs was vital, but somehow nothing has yet gone crazy.

You can pile up the preservation of any more folders, including network drives. Unless it is necessary to deal with the systemd parameters to configure the order of the launch of this case.

Source: https://habr.com/ru/post/272279/


All Articles