Permalink
Browse files

queue/daemon: Use a socket with nc(1) to avoid 'queue' needing write …

…access to the queue dir.

Currently the daemon reads from the socket and then writes the job
to the queue dir, and still uses dirwatch. This all may change in
the future still.
  • Loading branch information...
bdrewery committed May 24, 2013
1 parent c1a59a1 commit b246ee639df8107d31938573b9b4041732461849
Showing with 36 additions and 1 deletion.
  1. +1 −0 src/share/poudriere/common.sh
  2. +33 −0 src/share/poudriere/daemon.sh
  3. +2 −1 src/share/poudriere/queue.sh
@@ -2659,6 +2659,7 @@ esac
: ${WATCHDIR:=${POUDRIERE_DATA}/queue}
: ${PIDFILE:=${POUDRIERE_DATA}/daemon.pid}
: ${QUEUE_SOCKET:=/var/run/poudriered.sock}
BUILDNAME=$(date +%Y-%m-%d_%H:%M:%S)
@@ -36,6 +36,31 @@ Options:
exit 1
}
start_queue_reader() {
queue_reader_main &
QUEUE_READER_PID=$!
}
queue_reader_main() {
# Read from the socket and then write the command
# to the watchdir. This is done so non-privileged users
# do not need write access to the real queue dir
umask 0111 # Create rw-rw-rw
nc -klU ${QUEUE_SOCKET} | while read name command; do
echo "${command}" > ${WATCHDIR}/${name}
done
}
stop_queue_reader() {
if [ -n "${QUEUE_READER_PID}" ]; then
kill ${QUEUE_READER_PID} 2>/dev/null || :
wait ${QUEUE_READER_PID} 2>/dev/null || :
unset QUEUE_READER_PID
fi
rm -f ${QUEUE_SOCKET}
}
SCRIPTPATH=`realpath $0`
SCRIPTPREFIX=`dirname ${SCRIPTPATH}`
PTNAME="default"
@@ -74,6 +99,14 @@ if [ -z "${DAEMON_ARGS_PARSED}" ]; then
fi
fi
# Start the queue reader
start_queue_reader
CLEANUP_HOOK=daemon_cleanup
daemon_cleanup() {
stop_queue_reader
}
while :; do
next=$(find ${WATCHDIR} -type f -depth 1 -print -quit 2>/dev/null)
if [ -z "${next}" ]; then
@@ -45,4 +45,5 @@ bulk|testport) ;;
*) err 1 "$2 command cannot be queued" ;;
esac
echo "POUDRIERE_ARGS: $@" > ${WATCHDIR}/${name}
# Queue the command through the poudriered socket
echo "${name} POUDRIERE_ARGS: $@" | nc -U ${QUEUE_SOCKET}

0 comments on commit b246ee6

Please sign in to comment.