Skip to content

Commit

Permalink
Merge pull request #11337 from M0ses/improve_setup-appliance
Browse files Browse the repository at this point in the history
Improve setup appliance
  • Loading branch information
M0ses committed Jul 9, 2021
2 parents 37c70e1 + 14c0d87 commit 10fc850
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 29 deletions.
62 changes: 47 additions & 15 deletions dist/obs-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ Recommends: obs-service-verify_file

BuildRequires: systemd-rpm-macros


%{?systemd_requires}

%if 0%{?suse_version} >= 1500
BuildRequires: sysuser-tools
%endif

%description
The Open Build Service (OBS) backend is used to store all sources and binaries. It also
calculates the need for new build jobs and distributes it.
Expand Down Expand Up @@ -371,10 +374,27 @@ Provides: group(obsrun)
%if 0%{?suse_version:1}
Requires(pre): shadow
%endif
%if 0%{?suse_version} >= 1500
%sysusers_requires
%endif

%description -n system-user-obsrun
This package provides the system account and group 'obsrun'.

%if 0%{?suse_version} >= 1500
%pre -n system-user-obsrun -f obsrun.pre
%files -n system-user-obsrun
%{_sysusersdir}/system-user-obsrun.conf
%else
%pre -n system-user-obsrun
getent group obsrun >/dev/null || /usr/sbin/groupadd -r obsrun
getent passwd obsrun >/dev/null || \
/usr/sbin/useradd -r -g obsrun -d /usr/lib/obs -s %{sbin}/nologin \
-c "User for build service backend" obsrun

%files -n system-user-obsrun
%endif

%package -n system-user-obsservicerun
Summary: System user obsservicerun
Group: System/Fhs
Expand All @@ -383,10 +403,26 @@ Provides: user(obsservicerun)
%if 0%{?suse_version:1}
Requires(pre): shadow
%endif
%if 0%{?suse_version} >= 1500
%sysusers_requires
%endif


%description -n system-user-obsservicerun
This package provides the system account 'obsservicerun'

%if 0%{?suse_version} >= 1500
%pre -n system-user-obsservicerun -f obsservicerun.pre
%files -n system-user-obsservicerun
%{_sysusersdir}/system-user-obsservicerun.conf
%else
%pre -n system-user-obsservicerun
getent passwd obsservicerun >/dev/null || \
/usr/sbin/useradd -r -g obsrun -d %{obs_backend_data_dir}/service -s %{sbin}/nologin \
-c "" obsservicerun

%files -n system-user-obsservicerun
%endif
#--------------------------------------------------------------------------------
%prep
%setup -q -n open-build-service-%version
Expand Down Expand Up @@ -436,6 +472,11 @@ popd
#
make

%if 0%{?suse_version} >= 1500
%sysusers_generate_pre dist/system-user-obsrun.conf obsrun system-user-obsrun.conf
%sysusers_generate_pre dist/system-user-obsservicerun.conf obsservicerun system-user-obsservicerun.conf
%endif

%install
export DESTDIR=$RPM_BUILD_ROOT
export OBS_VERSION="%{version}"
Expand Down Expand Up @@ -503,6 +544,11 @@ DIR=%buildroot%perl_vendorlib/OBS
cp src/backend/BSXML.pm $DIR/XML.pm
sed -i -e 's,package BSXML;,package OBS::XML;,' $DIR/XML.pm

%if 0%{?suse_version} >= 1500
mkdir -p %{buildroot}%{_sysusersdir}
install -m 0644 dist/system-user-obsrun.conf %{buildroot}%{_sysusersdir}/
install -m 0644 dist/system-user-obsservicerun.conf %{buildroot}%{_sysusersdir}/
%endif

%check
%if 0%{?disable_obs_test_suite}
Expand Down Expand Up @@ -596,17 +642,6 @@ exit 0
%service_add_pre obsclouduploadworker.service
%service_add_pre obsclouduploadserver.service

%pre -n system-user-obsrun
getent group obsrun >/dev/null || /usr/sbin/groupadd -r obsrun
getent passwd obsrun >/dev/null || \
/usr/sbin/useradd -r -g obsrun -d /usr/lib/obs -s %{sbin}/nologin \
-c "User for build service backend" obsrun

%pre -n system-user-obsservicerun
getent passwd obsservicerun >/dev/null || \
/usr/sbin/useradd -r -g obsrun -d %{obs_backend_data_dir}/service -s %{sbin}/nologin \
-c "" obsservicerun

%preun
%service_del_preun obsscheduler.service
%service_del_preun obssrcserver.service
Expand Down Expand Up @@ -1066,7 +1101,4 @@ usermod -a -G docker obsservicerun
%dir %perl_vendorlib/OBS
%attr(0644,root,root) %perl_vendorlib/OBS/XML.pm

%files -n system-user-obsrun
%files -n system-user-obsservicerun

%changelog
19 changes: 17 additions & 2 deletions dist/setup-appliance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function adapt_worker_jobs {
function prepare_database_setup {

cd $apidir
RAILS_ENV=production bin/rails db:migrate:status > /dev/null
RAILS_ENV=production bin/rails db:migrate:status > /dev/null 2>&1

if [[ $? > 0 ]];then
echo "Initialize MySQL databases (first time only)"
Expand Down Expand Up @@ -691,6 +691,7 @@ ENABLE_OPTIONAL_SERVICES=0
ENABLE_FORCEPROJECTKEYS=1
MYSQL_USER=root
MYSQL_PASS=opensuse
PID_FILE=/run/setup-appliance.pid

# package or appliance defaults
if [ -e /etc/sysconfig/obs-server ]; then
Expand All @@ -709,9 +710,23 @@ fi


if [[ ! $BOOTSTRAP_TEST_MODE == 1 && $0 != "-bash" ]];then

logline "Starting "`basename $0`" at "`date`
NON_INTERACTIVE=0

if [ -f $PID_FILE ];then
APID=`cat $PID_FILE`
if [ ! -f /proc/$APID/status ];then
logline `basename $0`" died unexpectedly"
else
logline `basename $0`" already running. Exiting!"
exit 0
fi
fi

echo $$ > $PID_FILE

trap "rm -f $PID_FILE" EXIT

while [[ $1 ]];do
case $1 in
--non-interactive) NON_INTERACTIVE=1;;
Expand Down
4 changes: 4 additions & 0 deletions dist/system-user-obsrun.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Type Name ID GECOS [HOME]
g obsrun -
u obsrun 103 "User for build service backend" /usr/lib/obs
m obsrun obsrun
3 changes: 3 additions & 0 deletions dist/system-user-obsservicerun.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Type Name ID GECOS [HOME]
u obsservicerun - "User for build service obsservice daemon" /srv/obs/service
m obsservicerun obsrun
4 changes: 3 additions & 1 deletion dist/systemd/obs-clockwork.service
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[Unit]
Description = Open Build Service Clockwork Daemon
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
User = @@APACHE_USER@@
Group = @@APACHE_GROUP@@
WorkingDirectory = @@OBS_API_PREFIX@@
ExecStart = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_VERSION@@/bin/clockworkd --log-dir=log -l -c config/clock.rb start
ExecStop = @@OBS_BUNDLE_BIN@@ /usr/lib64/obs-api/ruby/@@OBS_RUBY_VERSION@@/bin/clockworkd -l -c config/clock.rb stop
ExecStop = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_VERSION@@/bin/clockworkd -l -c config/clock.rb stop
Type = forking
PIDFile = @@OBS_API_PREFIX@@/tmp/clockworkd.clock.pid

Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-consistency_check.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: consistency_check
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-default.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: default
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-issuetracking.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: issuetracking
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-mailers.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: mailers
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-project_log_rotate.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: project_log_rotate
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-quick@.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue Instance: quick
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-releasetracking.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: releasetracking
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-scm.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: scm
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
2 changes: 2 additions & 0 deletions dist/systemd/obs-delayedjob-queue-staging.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description = Open Build Service DelayedJob Queue: staging
BindsTo = obs-api-support.target
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
3 changes: 2 additions & 1 deletion dist/systemd/obs-sphinx.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Description = Open Build Service Sphinx Search Daemon
BindsTo = obs-api-support.target
Conflicts = searchd.service
After = obsapisetup.service
After = mariadb.service obsapisetup.service
Wants = mariadb.service obsapisetup.service

[Service]
Environment = "RAILS_ENV=production"
Expand Down
1 change: 1 addition & 0 deletions dist/systemd/obsapisetup.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ After=network-online.target mariadb.service
[Service]
Type=oneshot
ExecStart=/usr/lib/obs/server/setup-appliance.sh --non-interactive --setup-only
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
22 changes: 12 additions & 10 deletions dist/t/0060-check_required_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Test::More;
my $tests = 14;
my $max_wait = 300;

my @daemons = qw/obsdispatcher.service obspublisher.service obsrepserver.service
my @active_daemons = qw/obsdispatcher.service obspublisher.service obsrepserver.service
obsscheduler.service obssrcserver.service/;

my $out=`systemctl list-units`;
Expand All @@ -18,27 +18,29 @@ foreach my $unit (split(/\n/, $out)) {

die "could not find mariadb or mysql" if ! $mariadb;

push @daemons, $mariadb;
push @active_daemons, $mariadb;

my $os = get_distribution();
if ($os eq "suse") {
push @daemons, "apache2.service";
push @active_daemons, "apache2.service";
} elsif ($os eq 'rh') {
push @daemons, "httpd.service";
push @active_daemons, "httpd.service";
} else {
die "Could not determine distribution!\n";
}

my $version = `rpm -q --queryformat %{Version} obs-server`;

my @enabled_daemons = @active_daemons;

if ($version !~ /^2\.[89]\./) {
unshift @daemons, "obs-api-support.target";
$tests = 16;
push @active_daemons, 'obs-clockwork.service', 'obs-delayedjob-queue-consistency_check.service', 'obs-delayedjob-queue-default.service', 'obs-delayedjob-queue-issuetracking.service', 'obs-delayedjob-queue-mailers.service', 'obs-delayedjob-queue-project_log_rotate.service', 'obs-delayedjob-queue-quick@0.service', 'obs-delayedjob-queue-quick@1.service', 'obs-delayedjob-queue-quick@2.service', 'obs-delayedjob-queue-releasetracking.service', 'obs-delayedjob-queue-staging.service', 'obs-delayedjob-queue-scm.service', 'obs-sphinx.service';
$tests = $tests + 13;
}

plan tests => $tests;

foreach my $srv (@daemons) {
foreach my $srv (@enabled_daemons) {
my @state=`systemctl is-enabled $srv 2>/dev/null`;
my $result='';
if (@state) {
Expand All @@ -52,7 +54,7 @@ my %srv_state=();
while ($max_wait > 0) {
my $failed=0;
foreach my $srv (@daemons) {
foreach my $srv (@active_daemons) {
my @state=`systemctl is-active $srv 2>/dev/null`;
chomp($state[0]);
print "$srv $state[0]\n";
Expand All @@ -63,13 +65,13 @@ while ($max_wait > 0) {
$srv_state{$srv} = $state[0];
}
}
last if (keys(%srv_state) == scalar(@daemons));
last if (keys(%srv_state) == scalar(@active_daemons));
last if ($failed);
$max_wait--;
sleep 1;
}
foreach my $srv ( @daemons ) {
foreach my $srv ( @active_daemons ) {
is($srv_state{$srv} || 'timeout','active',"Checking recommended systemd unit '$srv' status");
}
Expand Down

0 comments on commit 10fc850

Please sign in to comment.