Skip to content

Commit

Permalink
[dist] obsapisetup as systemd service unit
Browse files Browse the repository at this point in the history
  • Loading branch information
M0ses authored and coolo committed Nov 14, 2018
1 parent 1f68018 commit 877ab6b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 118 deletions.
5 changes: 2 additions & 3 deletions dist/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include ../Makefile.include

INIT_SCRIPTS := obsscheduler obsworker obsapisetup obsstoragesetup
INIT_SCRIPTS := obsscheduler obsworker obsstoragesetup
LOGROTATE_CONFIGS := obs-api obs-server obs-source_service
OBS_BIN_SCRIPTS := obs_productconvert
OBS_SBIN_SCRIPTS := obs_admin obs_serverstatus
SYSTEMD_TARGET_FILES := obs-api-support
SYSTEMD_SERVICE_FILES := obs-clockwork obs-delayedjob-queue-project_log_rotate obs-delayedjob-queue-consistency_check obs-delayedjob-queue-default obs-delayedjob-queue-releasetracking obs-delayedjob-queue-issuetracking obs-delayedjob-queue-mailers obs-sphinx obsdeltastore obsdispatcher obsdodup obswarden obssrcserver obsrepserver obspublisher obssigner obsservice obsservicedispatch obsgetbinariesproxy obsclouduploadserver obsclouduploadworker
SYSTEMD_SERVICE_FILES := obs-clockwork obs-delayedjob-queue-project_log_rotate obs-delayedjob-queue-consistency_check obs-delayedjob-queue-default obs-delayedjob-queue-releasetracking obs-delayedjob-queue-issuetracking obs-delayedjob-queue-mailers obs-sphinx obsdeltastore obsdispatcher obsdodup obswarden obssrcserver obsrepserver obspublisher obssigner obsservice obsservicedispatch obsgetbinariesproxy obsclouduploadserver obsclouduploadworker obsapisetup
SYSTEMD_SERVICE_FILES_WITHOUT_LINK := obs-delayedjob-queue-quick@

FILLUPDIR := /var/adm/fillup-templates
Expand All @@ -17,7 +17,6 @@ install: install_obsapisetup install_apache install_initscripts install_project_
#install_overview

install_obsapisetup: system_dirs
$(INSTALL) -m 755 obsapisetup $(DESTDIR)/etc/init.d/obsapisetup
$(INSTALL) -m 755 setup-appliance.sh $(DESTDIR)$(OBS_BACKEND_PREFIX)/setup-appliance.sh

install_apache:
Expand Down
4 changes: 2 additions & 2 deletions dist/obs-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,7 @@ usermod -a -G docker obsservicerun
/srv/www/obs/api/config/application.rb
/srv/www/obs/api/config/clock.rb
%config(noreplace) /etc/logrotate.d/obs-api
/etc/init.d/obsapisetup
/usr/sbin/rcobsapisetup
%{_unitdir}/obsapisetup.service
%{_unitdir}/obs-api-support.target
%{_unitdir}/obs-clockwork.service
%{_unitdir}/obs-delayedjob-queue-consistency_check.service
Expand All @@ -731,6 +730,7 @@ usermod -a -G docker obsservicerun
%{_sbindir}/rcobs-delayedjob-queue-project_log_rotate
%{_sbindir}/rcobs-delayedjob-queue-releasetracking
%{_sbindir}/rcobs-sphinx
%{_sbindir}/rcobsapisetup
/srv/www/obs/api/app
%attr(-,%{apache_user},%{apache_group}) /srv/www/obs/api/db/structure.sql
%attr(-,%{apache_user},%{apache_group}) /srv/www/obs/api/db/data_schema.rb
Expand Down
70 changes: 0 additions & 70 deletions dist/obsapisetup

This file was deleted.

17 changes: 16 additions & 1 deletion dist/setup-appliance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ function get_hostname {
if [[ $1 && $BOOTSTRAP_TEST_MODE == 1 ]];then
FQHOSTNAME=$1
else
FQHOSTNAME=`hostname -f 2>/dev/null`
TIMEOUT=600
while [ -z "$FQHOSTNAME" ];do
FQHOSTNAME=`hostname -f 2>/dev/null`
TIMEOUT=$(($TIMEOUT-1))
[ "$TIMEOUT" -le 0 ] && break
echo "Waiting for FQHOSTNAME ($TIMEOUT)"
sleep 1
done
fi

if type -p ec2-public-hostname; then
Expand Down Expand Up @@ -608,10 +615,18 @@ if [[ ! $BOOTSTRAP_TEST_MODE == 1 && $0 != "-bash" ]];then
--non-interactive) NON_INTERACTIVE=1;;
--setup-only) SETUP_ONLY=1;;
--enable-optional-services) ENABLE_OPTIONAL_SERVICES=1;;
--force) OBS_API_AUTOSETUP="yes";;
esac
shift
done

if [ "$OBS_API_AUTOSETUP" != "yes" ]; then
echo "OBS API Autosetup is not enabled in sysconfig, skipping!"
exit 0
fi

[[ $HOME == '' ]] && export HOME=/root

# prepare configuration for obssigner before any other backend service
# is started, because obssigner configuration might affect other services
# too
Expand Down
11 changes: 11 additions & 0 deletions dist/systemd/obsapisetup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=OBS API Setup
Before=apache2.service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/lib/obs/server/setup-appliance.sh --non-interactive --setup-only

[Install]
WantedBy=multi-user.target
77 changes: 35 additions & 42 deletions dist/t/0050-test-appliance.ta
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
#!/bin/bash

export BOOTSTRAP_TEST_MODE=1
export NON_INTERACTIVE=1
export BASH_TAP_ROOT=$(dirname $0)

. $(dirname $0)/bash-tap-bootstrap

plan tests 2

for i in $(dirname $0)/../setup-appliance.sh /usr/lib/obs/server/setup-appliance.sh;do
[[ -f $i && -z $SETUP_APPLIANCE ]] && SETUP_APPLIANCE=$i
done

if [[ -z $SETUP_APPLIANCE ]];then
BAIL_OUT "Could not find setup appliance"
fi

. $SETUP_APPLIANCE

MAX_WAIT=300

tmpcount=$MAX_WAIT

# Service enabled and started
for srv in \
obsapisetup
do
STATE=` systemctl is-enabled $srv\.service 2>/dev/null`
is "$STATE" "enabled" "Checking $srv enabled"
ACTIVE=`systemctl is-active $srv\.service`
while [[ $ACTIVE != 'active' ]];do
tmpcount=$(( $tmpcount - 1 ))
ACTIVE=`systemctl is-active $srv\.service`
if [[ $tmpcount -le 0 ]];then
ACTIVE='timeout'
break
fi
sleep 1
done
is "$ACTIVE" "active" "Checking $srv status"
done
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

our @services = ('obsapisetup.service');

plan tests => 2 * scalar(@services);

my $TIMEOUT = 300;

for my $srv (@services) {
my $enabled = `systemctl is-enabled $srv 2>/dev/null`;
chomp($enabled);
is($enabled, 'enabled', "Checking $srv enabled");

my $success = 'timeout';
my $tmp = $TIMEOUT;

while ($tmp > 0) {
$tmp--;
my $result=`systemctl status $srv|grep "(code=exited, status=0/SUCCESS)"`;
if ($result) {
$success=$result;
last
}
print ".";
sleep 1;
}

like($success, qr/SUCCESS/, "Checking if $srv startup succeed");
}

exit 0;

0 comments on commit 877ab6b

Please sign in to comment.