Skip to content

Commit

Permalink
queue/daemon: Use a socket with nc(1) to avoid 'queue' needing write …
Browse files Browse the repository at this point in the history
…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 b246ee6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/share/poudriere/common.sh
Expand Up @@ -2659,6 +2659,7 @@ esac


: ${WATCHDIR:=${POUDRIERE_DATA}/queue} : ${WATCHDIR:=${POUDRIERE_DATA}/queue}
: ${PIDFILE:=${POUDRIERE_DATA}/daemon.pid} : ${PIDFILE:=${POUDRIERE_DATA}/daemon.pid}
: ${QUEUE_SOCKET:=/var/run/poudriered.sock}


BUILDNAME=$(date +%Y-%m-%d_%H:%M:%S) BUILDNAME=$(date +%Y-%m-%d_%H:%M:%S)


Expand Down
33 changes: 33 additions & 0 deletions src/share/poudriere/daemon.sh
Expand Up @@ -36,6 +36,31 @@ Options:
exit 1 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` SCRIPTPATH=`realpath $0`
SCRIPTPREFIX=`dirname ${SCRIPTPATH}` SCRIPTPREFIX=`dirname ${SCRIPTPATH}`
PTNAME="default" PTNAME="default"
Expand Down Expand Up @@ -74,6 +99,14 @@ if [ -z "${DAEMON_ARGS_PARSED}" ]; then
fi fi
fi fi


# Start the queue reader
start_queue_reader

CLEANUP_HOOK=daemon_cleanup
daemon_cleanup() {
stop_queue_reader
}

while :; do while :; do
next=$(find ${WATCHDIR} -type f -depth 1 -print -quit 2>/dev/null) next=$(find ${WATCHDIR} -type f -depth 1 -print -quit 2>/dev/null)
if [ -z "${next}" ]; then if [ -z "${next}" ]; then
Expand Down
3 changes: 2 additions & 1 deletion src/share/poudriere/queue.sh
Expand Up @@ -45,4 +45,5 @@ bulk|testport) ;;
*) err 1 "$2 command cannot be queued" ;; *) err 1 "$2 command cannot be queued" ;;
esac 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.