Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.6.0 #32

Merged
merged 8 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ ratings:
- SOURCES/rpmbuilder
- SOURCES/rpmunbuilder
- SOURCES/buildmon
- SOURCES/initenv
49 changes: 30 additions & 19 deletions SOURCES/buildmon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
###############################################################################

APP="RPMBuilder Node Monitor"
VER="1.1.0"
VER="1.1.1"

###############################################################################

BUILDER_USER="builder"
BUILDER_DIR="/home/builder"
EXEC="$BUILDER_DIR/buildmon"
BUILD_LOCK="$BUILDER_DIR/.buildlock"
CLEAN_DELAY=600
KEEP_DAYS=7 # 1 Week
CLEAN_PERIOD=600 # 10 Min
MAX_KEEP_DAYS=7 # 1 Week
DIR_LIST="BUILD BUILDROOT RPMS SOURCES SPECS SRPMS"

CWD=$(pwd)
Expand All @@ -21,40 +21,51 @@ CWD=$(pwd)

main() {
trap doExit SIGINT SIGTERM

check

doExit
}

check() {
local has_lock
local dl

dl=0
local counter=0

while : ; do
sleep 1
sleep 3

if [[ $(pgrep -U $BUILDER_USER rpmbuild) ]] ; then
touch $BUILD_LOCK
has_lock=true
if isBuildInProgress ; then
touch "$BUILD_LOCK"
else
if [[ $has_lock ]] ; then
rm -f $BUILD_LOCK
has_lock=""
if [[ -n "$has_lock" ]] ; then
rm -f "$BUILD_LOCK"
fi
fi

((dl++))
((counter++))

if [[ $dl -eq $CLEAN_DELAY ]] ; then
dl=0 ; clean
if [[ $counter -gt $CLEAN_PERIOD ]] ; then
counter=0
clean
fi
done
}

isBuildInProgress() {
if [[ $(pgrep -U "$BUILDER_USER" "rpmbuild") ]] ; then
return 0
fi

if [[ $(pgrep -U "$BUILDER_USER" "yum-builddep") ]] ; then
return 0
fi

return 1
}

clean() {
local rbdir="$BUILDER_DIR/rpmbuild"
find $rbdir -maxdepth 1 -type d -mtime +$KEEP_DAYS -delete
for dir in $DIR_LIST ; do
find "$BUILDER_DIR/rpmbuild/$dir" -maxdepth 1 -mtime +$MAX_KEEP_DAYS -delete
done
}

doExit() {
Expand Down
29 changes: 29 additions & 0 deletions SOURCES/initenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

###############################################################################

APP="Build Env Init"
VER="1.0.0"

###############################################################################

BUILDER_HOME="/home/builder"

###############################################################################

main() {
initEnv &> /dev/null
}

initEnv() {
mkdir -p "$BUILDER_HOME/rpmbuild/BUILD"
mkdir -p "$BUILDER_HOME/rpmbuild/BUILDROOT"
mkdir -p "$BUILDER_HOME/rpmbuild/RPMS"
mkdir -p "$BUILDER_HOME/rpmbuild/SOURCES"
mkdir -p "$BUILDER_HOME/rpmbuild/SPECS"
mkdir -p "$BUILDER_HOME/rpmbuild/SRPMS"
}

###############################################################################

main "$@"
Loading