diff --git a/Makefile b/Makefile index 77ef4ca..8a76cc8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -images=agate archivebox ansible backup buku ddclient git-daemon gitolite gitolite-pystagit rss-bridge pleroma sassc syncthing tasks tor transmission vdirsyncer xandikos +images=agate archivebox ansible backup buku ddclient git-daemon gitolite gitolite-pystagit rss-bridge pleroma sassc syncthing tasks tor transmission vdirsyncer xandikos nfs-server .PHONY: all $(images) all: $(images) @@ -31,6 +31,9 @@ gitolite: gitolite-pystagit: $(BUILD) +nfs-server: + $(BUILD) + rss-bridge: $(BUILD) diff --git a/README.md b/README.md index 0c1ebac..4256944 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ useful. * gitolite-pystagit: well, gitolite + pystagit * gitolite: gitolite + docker, so that I can mount the docker socket inside of it and have it do useful things through docker in response to triggers +* nfs-server * pleroma * sassc * syncthing diff --git a/nfs-server/Dockerfile b/nfs-server/Dockerfile new file mode 100644 index 0000000..bff5b3e --- /dev/null +++ b/nfs-server/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.13 + +COPY entrypoint.sh /usr/local/bin/entrypoint + +RUN apk add --no-cache nfs-utils && \ + rm /etc/idmapd.conf /etc/exports && \ + mkdir -p /var/lib/nfs/rpc_pipefs /var/lib/nfs/v4recovery && \ + echo "rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0" >> /etc/fstab && \ + echo "nfsd /proc/fs/nfsd nfsd defaults 0 0" >> /etc/fstab && \ + chmod +x /usr/local/bin/entrypoint + +EXPOSE 2049 +ENTRYPOINT ["/usr/local/bin/entrypoint"] + + diff --git a/nfs-server/Makefile b/nfs-server/Makefile new file mode 100644 index 0000000..dd14738 --- /dev/null +++ b/nfs-server/Makefile @@ -0,0 +1,10 @@ +USERNAME = rilla +IMG_NAME = nfs-server + +.PHONY: build build-nc + +build: Dockerfile entrypoint.sh + docker build -t $(USERNAME)/$(IMG_NAME) . + +build-nc: Dockerfile entrypoint.sh + docker build --no-cache -t $(USERNAME)/$(IMG_NAME) . diff --git a/nfs-server/entrypoint.sh b/nfs-server/entrypoint.sh new file mode 100644 index 0000000..7ad9a99 --- /dev/null +++ b/nfs-server/entrypoint.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +NTHREADS=${NTHREADS:=1} + +stop () { + echo "un-exporting filesystems" + /usr/sbin/exportfs -uav + + echo "terminating nfsd" + /usr/sbin/rpc.nfsd 0 + + echo "killing pids" + pid1=$(pidof rpc.nfsd) + pid2=$(pidof rpc.mountd) + pid3=$(pidof rpc.rpcbind) + kill -TERM "$pid1" "$pid2" "$pid3" + + echo "un-mounting /var/lib/nfs/rpc_pipefs" + umount /var/lib/nfs/rpc_pipefs + + echo "un-mounting /proc/nfs/nfsd" + umount /proc/fs/nfsd + + exit 0 +} + +boot () { + + echo "mounting /var/lib/nfs/rpc_pipefs" + /bin/mount -t rpc_pipefs /var/lib/nfs/rpc_pipefs + echo "mounting /proc/fs/nfsd" + /bin/mount -t nfsd /proc/fs/nfsd + + echo "starting rpcbind" + /sbin/rpcbind -sw + /sbin/rpcinfo + + echo "exporting filesystems" + /usr/sbin/exportfs -ar + cat /etc/exports + + echo "starting mountd" + /usr/sbin/rpc.mountd \ + --port 32767 \ + --nfs-version 4 \ + --no-nfs-version 2 \ + --no-nfs-version 3 + + echo "starting nfsd" + /usr/sbin/rpc.nfsd \ + --tcp \ + --udp \ + --port 2049 \ + --nfs-version 4 \ + --no-nfs-version 2 \ + --no-nfs-version 3 \ + "${NTHREADS}" + + echo "terminating rpcbind" + pid=$(pidof rpcbind) + [ -n "$pid" ] && kill "$pid" + + echo "ready" +} + +trap stop TERM INT +boot + +while :; do + sleep 2073600 & + wait +done