Skip to content

Commit

Permalink
Merge pull request #1838 from M0ses/improve_databasesetup_in_setup-ap…
Browse files Browse the repository at this point in the history
…pliance

Improve databasesetup in setup appliance
  • Loading branch information
adrianschroeter committed May 30, 2016
2 parents b61bb75 + 9c0d3a1 commit ba24f8a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
68 changes: 63 additions & 5 deletions dist/obsstoragesetup
Expand Up @@ -141,6 +141,7 @@ case "$1" in
echo "Remove all LVM cache and worker partitions in VG OBS."
# Cannot test on existence of "/dev/OBS", in case no LVs in VG OBS have been created!
if [ -n "$(vgdisplay -c OBS 2>/dev/null)" ]; then
vgchange -ay OBS
lvremove -f /dev/OBS/worker_* /dev/OBS/cache 2>/dev/null
else
echo "WARNING: The LVM volume group 'OBS' can not be used."
Expand All @@ -152,7 +153,37 @@ case "$1" in
[ -d "$backenddir" ] || mkdir -p "$backenddir"
if [ -e /dev/OBS/server ]; then
mount /dev/OBS/server "$backenddir"
if [ -e /usr/lib/obs/server/BSConfig.pm ];then
echo "Found BSConfig.pm"
if [ -d "$backenddir/run" ]; then
echo "Directory '$backenddir/run' exists"
# make sure that directories needed by mostly all other daemons are created now
# and set proper ownership
bsuser=`perl -I/usr/lib/obs/server -MBSConfig -e 'print ( $BSConfig::bsuser || "obsrun" )'`
bsgroup=`perl -I/usr/lib/obs/server -MBSConfig -e 'print ( $BSConfig::bsgroup || "obsrun" )'`
owner_rundir=`stat -L --printf="%U" "$backenddir/run"`
if [ "$owner_rundir" != "root" ];then
echo "owner of '$backenddir/run' is $owner_rundir"
if [ "$owner_rundir" != "$bsuser" ];then
echo "owner $owner_rundir is not configured bsuser '$bsuser'"
echo "changing ownership"
uid_rundir=`stat -L --printf="%u" "$backenddir/run"`
find $backenddir -uid $uid_rundir -exec chown $bsuser:$bsgroup {} \;
else
echo "Owner of '$backenddir/run' is '$bsuser'. Nothing to fix!"
fi
else
echo "Owner of '$backenddir/run' is root. Not changing anything"
fi
else
echo "Directory '$backenddir/run' not found"
fi
else
echo "No BSConfig found while setting up /dev/OBS/server"
fi
obs_server_size=$(( $(lvdisplay -c OBS/server 2>/dev/null | cut -d: -f7) / 2 / 1024 ))
else
echo "No logical volume found under /dev/OBS/server"
fi

# setup signer and signd if possible
Expand Down Expand Up @@ -215,11 +246,25 @@ case "$1" in

if [ -z "$OBS_WORKER_ROOT_SIZE" ]; then
VG_SIZE=`vgdisplay -c OBS | cut -d: -f16`
VG_SIZE=$(( $VG_SIZE * ( $PE_SIZE / 1024 ) ))
VG_SIZE=$(( $VG_SIZE - ${obs_server_size:-0} - $OBS_WORKER_CACHE_SIZE - ( $NUM * $OBS_WORKER_SWAP_SIZE ) ))
OBS_WORKER_ROOT_SIZE=$(( $VG_SIZE / $NUM ))
PE_SIZE_IN_MB=$(( $PE_SIZE / 1024 ))
VG_SIZE=$(( $VG_SIZE * $PE_SIZE_IN_MB ))
OBS_SERVER_SIZE=${obs_server_size:-0}
TOTAL_SWAP_SIZE=$(( $NUM * $OBS_WORKER_SWAP_SIZE ))
FINAL_VG_SIZE=$(( $VG_SIZE - $OBS_SERVER_SIZE - $OBS_WORKER_CACHE_SIZE - $TOTAL_SWAP_SIZE ))
OBS_WORKER_ROOT_SIZE=$(( $FINAL_VG_SIZE / $NUM ))
MIN_WORKER_ROOT_SIZE=$(( 4 * 1024 ))
if test $OBS_WORKER_ROOT_SIZE -lt $(( 4 * 1024 )); then
echo "ERROR: Not enough space for worker root LVs, just $OBS_WORKER_ROOT_SIZE MB, but at least 4 GB needed."
echo "NUM=$NUM"
echo "VG_SIZE=$VG_SIZE"
echo "PE_SIZE=$PE_SIZE"
echo "PE_SIZE_IN_MB=$PE_SIZE_IN_MB"
echo "OBS_SERVER_SIZE=$OBS_SERVER_SIZE"
echo "TOTAL_SWAP_SIZE=$TOTAL_SWAP_SIZE"
echo "FINAL_VG_SIZE = $VG_SIZE - $OBS_SERVER_SIZE - $OBS_WORKER_CACHE_SIZE - $TOTAL_SWAP_SIZE"
echo "FINAL_VG_SIZE=$FINAL_VG_SIZE";
echo "OBS_WORKER_ROOT_SIZE=$OBS_WORKER_ROOT_SIZE"
echo "MIN_WORKER_ROOT_SIZE=$MIN_WORKER_ROOT_SIZE"
exit 1
fi
fi
Expand All @@ -240,14 +285,26 @@ case "$1" in

lverr=$(mktemp)
if ! lvcreate --wipesignatures y -n worker_root_${I} -L ${OBS_WORKER_ROOT_SIZE}M OBS ${pvs[$(( $pv_idx + $o1 ))]} 2> $lverr; then
if [ $? -gt 0 ];then
echo "An error occured while creating LV"
cat $lverr
else
echo "Creation of worker_root_${I} succeed"
fi
if grep "Insufficient free space" $lverr; then
I=$(( $I - 1 ))
else
cat $lverr >&2
exit
fi
else
lvcreate --wipesignatures y -n worker_swap_${I} -L ${OBS_WORKER_SWAP_SIZE}M OBS ${pvs[$(( $pv_idx + $o2 ))]} || exit
lvcreate --wipesignatures y -n worker_swap_${I} -L ${OBS_WORKER_SWAP_SIZE}M OBS ${pvs[$(( $pv_idx + $o2 ))]}
if [ $? -gt 0 ];then
echo "An error occured while creating LV worker_swap_${I} "
exit 1
else
echo "Creation of worker_swap_${I} succeed"
fi
fi
rm -f $lverr
pv_idx=$(( $pv_idx + 2 ))
Expand Down Expand Up @@ -402,7 +459,8 @@ case "$1" in
bsgroup=`perl -I/usr/lib/obs/server -MBSConfig -e 'print ( $BSConfig::bsgroup || "obsrun" )'`
[ -d $backenddir/run ] || mkdir -p $backenddir/run
[ -d $backenddir/log ] || mkdir -p $backenddir/log
chown $bsuser:$bsgroup $backenddir $backenddir/run $backenddir/log
# fix ownership
chown $bsuser:$bsgroup $backenddir
fi

# offer hook to make random special things in your setup
Expand Down
11 changes: 9 additions & 2 deletions dist/setup-appliance.sh
Expand Up @@ -230,11 +230,18 @@ function adapt_worker_jobs {
}
###############################################################################
function prepare_database_setup {
DATABASE_EXISTS=$(mysql -e "show databases"|grep api_production)

cd /srv/www/obs/api
RAILS_ENV=production rake.ruby2.3 db:migrate:status > /dev/null

if [[ ! $DATABASE_EXISTS ]];then
if [[ $? > 0 ]];then
echo "Initialize MySQL databases (first time only)"
mysqladmin -u root password "opensuse"
if [[ $? > 0 ]];then
echo "ERROR: Your mysql setup doesn't fit your rails setup"
echo "Please check your database settings for mysql and rails"
exit 1
fi
RUN_INITIAL_SETUP="true"
fi

Expand Down

0 comments on commit ba24f8a

Please sign in to comment.