From 7619dc0bef58d00c816b6628e457a85845b9edee Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 26 Nov 2022 12:59:28 +0100 Subject: Cleanup via cron/systemd --- Makefile | 14 +++++++++++--- config.cpp | 2 +- debian/README.Debian | 7 +++++++ debian/control | 2 +- debian/dirs | 1 - debian/rules | 6 ++++++ debian/whiteboard.conf | 3 --- debian/whiteboard.dirs | 1 + debian/whiteboard.install | 1 - debian/whiteboard.service | 13 ------------- debian/whiteboard.whiteboard-cleanup.service | 10 ++++++++++ debian/whiteboard.whiteboard-cleanup.timer | 10 ++++++++++ debian/whiteboard.whiteboard.service | 13 +++++++++++++ whiteboard-cleanup | 24 ++++++++++++++++++++++++ whiteboard.conf | 13 ++++++++++++- whiteboard.cron | 2 ++ 16 files changed, 98 insertions(+), 24 deletions(-) delete mode 100644 debian/dirs delete mode 100644 debian/whiteboard.conf create mode 100644 debian/whiteboard.dirs delete mode 100644 debian/whiteboard.install delete mode 100644 debian/whiteboard.service create mode 100644 debian/whiteboard.whiteboard-cleanup.service create mode 100644 debian/whiteboard.whiteboard-cleanup.timer create mode 100644 debian/whiteboard.whiteboard.service create mode 100755 whiteboard-cleanup create mode 100644 whiteboard.cron diff --git a/Makefile b/Makefile index 640a081..a387f1c 100755 --- a/Makefile +++ b/Makefile @@ -67,14 +67,22 @@ all: build install: mkdir -p $(DESTDIR)/usr/lib/whiteboard cp whiteboard.fcgi $(DESTDIR)/usr/lib/whiteboard/ - + mkdir -p $(DESTDIR)/usr/lib/whiteboard/html cp -r html/* $(DESTDIR)/usr/lib/whiteboard/html/ - + uglifyjs html/whiteboard.js -m -c > $(DESTDIR)/usr/lib/whiteboard/html/whiteboard.js htmlmin html/index.html $(DESTDIR)/usr/lib/whiteboard/html/index.html cleancss -o $(DESTDIR)/usr/lib/whiteboard/html/whiteboard.css html/whiteboard.css - + + mkdir -p $(DESTDIR)/etc + cp whiteboard.conf $(DESTDIR)/etc + + mkdir -p $(DESTDIR)/usr/bin + cp whiteboard-cleanup $(DESTDIR)/usr/bin/ + + mkdir -p $(DESTDIR)/etc/cron.d + cp whiteboard.cron $(DESTDIR)/etc/cron.d/whiteboard whiteboard.fcgi: $(OBJECTS) diff --git a/config.cpp b/config.cpp index 6e2e2b6..e3ef68f 100644 --- a/config.cpp +++ b/config.cpp @@ -20,7 +20,7 @@ Config::Config(): m_dataPath{default_datapath} pt::read_xml(config_filename, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); - m_dataPath = tree.get("whiteboard.datapath", default_datapath); + m_dataPath = tree.get("config.datapath", default_datapath); } catch (const std::exception& ex) { std::cerr << "Error reading config file " << config_filename << ". Using " << default_datapath << "." << std::endl; } diff --git a/debian/README.Debian b/debian/README.Debian index f3f2434..07ab4d6 100644 --- a/debian/README.Debian +++ b/debian/README.Debian @@ -3,6 +3,10 @@ whiteboard for Debian This package is the Debian version of whiteboard. +It is an FCGI application communicating to a webserver, e.g. Reichwein.IT webserver. + +Via cron or systemd, whiteboard data in /var/lib/whiteboard is cleaned up once a day. +Data location and maximum data age can be configured via /etc/whiteboard.conf. Configuration ------------- @@ -18,6 +22,9 @@ Configuration 127.0.0.1:9014 +* Edit /etc/whiteboard.conf to adjust the whiteboard data path if different + from /var/lib/whiteboard + * Enable: # systemctl enable whiteboard.service diff --git a/debian/control b/debian/control index dc159fa..62b6e4c 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Homepage: http://www.reichwein.it/whiteboard/ Package: whiteboard Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, spawn-fcgi +Depends: ${shlibs:Depends}, ${misc:Depends}, spawn-fcgi, libxml2-utils Recommends: webserver Homepage: http://www.reichwein.it/whiteboard/ Description: Web application for an collaborative editor diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index 7b03c85..0000000 --- a/debian/dirs +++ /dev/null @@ -1 +0,0 @@ -var/lib/whiteboard diff --git a/debian/rules b/debian/rules index 9f52133..2ee2604 100755 --- a/debian/rules +++ b/debian/rules @@ -6,3 +6,9 @@ override_dh_fixperms: dh_fixperms chmod a+rwx debian/whiteboard/var/lib/whiteboard + + +override_dh_auto_install: + dh_auto_install + dh_installsystemd --name whiteboard + dh_installsystemd --name whiteboard-cleanup diff --git a/debian/whiteboard.conf b/debian/whiteboard.conf deleted file mode 100644 index 91a868a..0000000 --- a/debian/whiteboard.conf +++ /dev/null @@ -1,3 +0,0 @@ - - /var/lib/whiteboard - diff --git a/debian/whiteboard.dirs b/debian/whiteboard.dirs new file mode 100644 index 0000000..7b03c85 --- /dev/null +++ b/debian/whiteboard.dirs @@ -0,0 +1 @@ +var/lib/whiteboard diff --git a/debian/whiteboard.install b/debian/whiteboard.install deleted file mode 100644 index fa446b2..0000000 --- a/debian/whiteboard.install +++ /dev/null @@ -1 +0,0 @@ -debian/whiteboard.conf etc diff --git a/debian/whiteboard.service b/debian/whiteboard.service deleted file mode 100644 index c60f3f0..0000000 --- a/debian/whiteboard.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Whiteboard -After=network.target - -[Service] -Type=simple -# Restart=always -ExecStart=spawn-fcgi -a 127.0.0.1 -p 9014 -n -- /usr/lib/whiteboard/whiteboard.fcgi - -Restart=always - -[Install] -WantedBy=multi-user.target diff --git a/debian/whiteboard.whiteboard-cleanup.service b/debian/whiteboard.whiteboard-cleanup.service new file mode 100644 index 0000000..339c143 --- /dev/null +++ b/debian/whiteboard.whiteboard-cleanup.service @@ -0,0 +1,10 @@ +[Unit] +Description=Cleanup whiteboard data +Wants=whiteboard-cleanup.timer + +[Service] +Type=oneshot +ExecStart=/usr/bin/whiteboard-cleanup + +[Install] +WantedBy=multi-user.target diff --git a/debian/whiteboard.whiteboard-cleanup.timer b/debian/whiteboard.whiteboard-cleanup.timer new file mode 100644 index 0000000..e2c93f9 --- /dev/null +++ b/debian/whiteboard.whiteboard-cleanup.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Clean up whiteboard data +Requires=whiteboard-cleanup.service + +[Timer] +Unit=whiteboard-cleanup.service +OnCalendar=*-*-* 00:00:00 + +[Install] +WantedBy=timers.target diff --git a/debian/whiteboard.whiteboard.service b/debian/whiteboard.whiteboard.service new file mode 100644 index 0000000..c60f3f0 --- /dev/null +++ b/debian/whiteboard.whiteboard.service @@ -0,0 +1,13 @@ +[Unit] +Description=Whiteboard +After=network.target + +[Service] +Type=simple +# Restart=always +ExecStart=spawn-fcgi -a 127.0.0.1 -p 9014 -n -- /usr/lib/whiteboard/whiteboard.fcgi + +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/whiteboard-cleanup b/whiteboard-cleanup new file mode 100755 index 0000000..7a987e0 --- /dev/null +++ b/whiteboard-cleanup @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Cleanup global whiteboard files +# +# To be called by cron +# + +set -e + +# look up config file +CONFIGFILE=/etc/whiteboard.conf +XMLLINTOPTS="--nonet --nocdata --nocatalogs" +DATAPATH=`xmllint --xpath "/config/datapath/text()" $XMLLINTOPTS $CONFIGFILE` +MAXAGE=`xmllint --xpath "/config/maxage/text()" $XMLLINTOPTS $CONFIGFILE` + +cd $DATAPATH + +ls -1 | while read i ; do + AGE=$((`date +"%s"` - `stat -c "%Y" $i`)) + if [[ "$AGE" -gt "$MAXAGE" ]] ; then + echo "Deleting entry $i ..." + rm $i + fi +done diff --git a/whiteboard.conf b/whiteboard.conf index d269e46..80ae173 100644 --- a/whiteboard.conf +++ b/whiteboard.conf @@ -1,3 +1,14 @@ - /home/ernie/code/whiteboard/data + + /var/lib/whiteboard + + + 2592000 diff --git a/whiteboard.cron b/whiteboard.cron new file mode 100644 index 0000000..705c2eb --- /dev/null +++ b/whiteboard.cron @@ -0,0 +1,2 @@ +# Cleanup whiteboard data once every day +02,31 * * * * root [ -x /usr/bin/whiteboard-cleanup ] && if [ ! -d /run/systemd/system ]; then /usr/bin/whiteboard-cleanup ; fi -- cgit v1.2.3