-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
136 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
resel-nsa-0.4/debian/changelog → resel-nsa-0.5/debian/changelog
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
resel-nsa (0.5-1) UNRELEASED; urgency=low | ||
|
||
* Add multiprocessing capabilities, | ||
* Add log rotation, | ||
* Improve code quality. | ||
|
||
-- Benjamin Somers <[email protected]> Wed, 14 Oct 2020 23:22:00 +0200 | ||
|
||
resel-nsa (0.4-1) UNRELEASED; urgency=low | ||
|
||
* Add a manager to simplify administrative tasks and create manpages. | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
etc/* etc | ||
var/* var | ||
usr/* usr |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/var/log/resel-nsa/nsa-send { | ||
compress | ||
nocreate | ||
daily | ||
notifempty | ||
rotate 7 | ||
missingok | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#LOG_DATE_FORMAT=<Date Format> | ||
#TOKEN=<Default WRITE Token> | ||
#ENDPOINT=<Warp 10 Endpoint> | ||
#SEND_JOBS=<Ingress Jobs> | ||
#SEND_TIMEOUT=<Ingress Timeout> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
|
||
if [ -f /etc/nsa/.disable ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
shopt -s nullglob | ||
set -aeu | ||
LOG_DIR=/var/log/resel-nsa | ||
LOG_DATE_FORMAT='%Y-%m-%d %H:%M:%S' | ||
SEND_JOBS=$(getconf _NPROCESSORS_ONLN) | ||
SEND_TIMEOUT=1m | ||
source /etc/nsa/config | ||
|
||
declare -A DURATIONS | ||
DURATIONS=([s]=1 [m]=60 [h]=3600) | ||
TIMEOUT_VALUE=${SEND_TIMEOUT::-1} | ||
TIMEOUT_SUFFIX=${SEND_TIMEOUT: -1} | ||
TIMEOUT=$((TIMEOUT_VALUE * ${DURATIONS[$TIMEOUT_SUFFIX]})) | ||
set +a | ||
|
||
open_semaphore() | ||
{ | ||
fifo=/var/spool/nsa/pipe-$$ | ||
mkfifo $fifo | ||
exec 3<>/$fifo | ||
rm $fifo | ||
local i=$1 | ||
for ((; i>0; i--)) | ||
do | ||
printf %s 000 >&3 | ||
done | ||
} | ||
|
||
run_job() | ||
{ | ||
read -u 3 -n 3 -r code && ((0==code)) || exit "$code" | ||
( | ||
timeout_dir=/var/spool/nsa/timeout/$3 | ||
mkdir -p "$timeout_dir" | ||
{ | ||
sleep $TIMEOUT | ||
echo "[$(date +"$LOG_DATE_FORMAT")] sending $2 timed out" >> "$LOG_DIR/nsa-send" | ||
mv "/var/spool/nsa/sending/$3/$2" "$timeout_dir" | ||
kill $BASHPID | ||
}& | ||
timer_pid=$! | ||
( "$@"; ) | ||
kill $timer_pid | ||
printf '%.3d' $? >&3 | ||
)& | ||
} | ||
|
||
process() | ||
{ | ||
error_dir=/var/spool/nsa/error/$2 | ||
sending_dir=/var/spool/nsa/sending/$2 | ||
mkdir -p "$error_dir" | ||
file="$sending_dir/$1" | ||
source "/etc/nsa/profiles.d/$2" | ||
echo "[$(date +"$LOG_DATE_FORMAT")] processing $1" >> "$LOG_DIR/nsa-send" | ||
if [ ! -s "$file" ] || ([ -f "$file" ] && curl -fs -H "X-Warp10-Token: $TOKEN" -H 'Transfer-Encoding: chunked' -T "$file" "$ENDPOINT") | ||
then | ||
rm -f "$file" | ||
echo "[$(date +"$LOG_DATE_FORMAT")] $1 sent" >> $LOG_DIR/nsa-send | ||
else | ||
mv "$file" "$error_dir" | ||
echo "[$(date +"$LOG_DATE_FORMAT")] $1 moved to error pool" >> $LOG_DIR/nsa-send | ||
fi | ||
} | ||
|
||
open_semaphore "$SEND_JOBS" | ||
for dir in /var/spool/nsa/ready/* | ||
do | ||
if [ -d "$dir" ] | ||
then | ||
category=$(basename "$dir") | ||
ready_dir=/var/spool/nsa/ready/$category | ||
sending_dir=/var/spool/nsa/sending/$category | ||
mkdir -p "$sending_dir" | ||
files=("$ready_dir"/*) | ||
for ((i=${#files[@]}-1; i>=0; i--)) | ||
do | ||
file=$(basename "${files[$i]}") | ||
mv "$ready_dir/$file" "$sending_dir" | ||
run_job process "$file" "$category" | ||
done | ||
fi | ||
done |
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.