Last active
April 4, 2023 19:20
-
-
Save ohmantics/d09ba88eeb73f7a52c1c1f4bbc75e793 to your computer and use it in GitHub Desktop.
FreeBSD jail to watch a directory and make files appear atomically for paperless-ngx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo iocage create -n watcher -r 13.1-RELEASE vnet=on ip4=disable ip6=disable boot=on | |
sudo mkdir /mnt/tank/iocage/jails/watcher/root/mnt/paperless | |
sudo iocage fstab watcher -a "/mnt/tank/paperless/paperless /mnt/paperless nullfs rw 0 0" | |
sudo pkg --chroot /mnt/tank/iocage/jails/watcher/root install inotify-tools | |
# install the two files below | |
sudo iocage start watcher | |
sudo iocage exec watcher sysrc watcher_enable="YES" | |
###########################Put in /usr/local/bin/watcher.sh | |
#!/bin/sh | |
monitorDir="/mnt/paperless/consume1st" | |
# Watch monitorDir for files to appear and finish writing, then move them to the consume directory | |
/usr/local/bin/inotifywait -q -m -r -e close_write --format '%w%f' "$monitorDir" | while read newObject | |
do | |
if [ ! -d "$newObject" ]; then | |
case $newObject in | |
*.pdf) mv "$newObject" /mnt/paperless/consume && logger "moved $newObject" ;; | |
esac | |
fi | |
done | |
###########################Put in /usr/local/etc/rc.d/watcher | |
#!/bin/sh | |
# PROVIDE: watcher | |
# REQUIRE: mountlate securelevel | |
# Add the following lines to /etc/rc.conf to enable `watcher': | |
# | |
# watcher_enable="YES" | |
. /etc/rc.subr | |
name="watcher" | |
rcvar=`set_rcvar` | |
load_rc_config $name | |
: ${watcher_enable="NO"} | |
pidfile="/var/run/${name}.pid" | |
command="/usr/sbin/daemon" | |
command_args="-c -f -R 3 -P ${pidfile} /usr/local/bin/${name}.sh" | |
required_files="/usr/local/bin/${name}.sh" | |
start_precmd="watcher_precmd" | |
watcher_precmd() | |
{ | |
install -o root /dev/null ${pidfile} | |
} | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment