Skip to content

Commit

Permalink
Merge pull request #32 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
andyone authored Mar 3, 2017
2 parents 39cb323 + 6b9e128 commit 116d986
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 85 deletions.
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

0 comments on commit 116d986

Please sign in to comment.