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

FIX #214 Making rpm scriptlets overrideable #219

Merged
merged 6 commits into from
Apr 11, 2014

Conversation

muuki88
Copy link
Contributor

@muuki88 muuki88 commented Apr 6, 2014

@aparkinson can you take a look at this :)

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 8, 2014

A debian test fails: debian / override-control-files. Also recheck the rpm scriplets

@timperrett
Copy link

@muuki88 we are hitting the issue with the missing useradd in the rpmPre - we just tried building this branch and it still doesnt work to produce the desired outcome; rpms still dont have the preinstall macro specified. Any ideas?

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 8, 2014

Hi @timperrett , thanks for reporting. I will make further investigations tomorrorw. This is pretty serious.

@timperrett
Copy link

@muuki88 - thanks; this is a pretty major issue for us so any advice would be welcome :-)

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 9, 2014

This two fixes should solve the rpm-server issue. I also added as @aparkinson mentioned a way to add the service to autostart with chkconfig or update-rc.d.

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 9, 2014

I justed tested this agaings CentOS 6. @aparkinson Can you try if the update-rc.d works fine on RHEL, too?

@timperrett
Copy link

@muuki88 Is this actually fixed? After checking out the wip/rpm-template-overrides branch and building an RPM, I see the following scripts embedded in the RPM:

λ rpm -qp --scripts http/target/rpm/RPMS/noarch/http-3.2.6bcedba-0.noarch.rpm
postinstall scriptlet (using /bin/sh):
#
# Adding oncue to autostart
#
addservice() {
    if hash update-rc.d 2>/dev/null; then
        echo "Adding oncue to autostart using update-rc.d"
        update-rc.d oncue defaults
    elif chkconfig 2>/dev/null; then
        echo "Adding oncue to autostart using chkconfig"
        chkconfig --add oncue
        chkconfig oncue on
    else
        echo "WARNING: Could not put oncue in autostart"
    fi
}

addservice
service oncue start
preuninstall scriptlet (using /bin/sh):
# Halting oncue
echo "Shutdown oncue"
service oncue stop
postuninstall scriptlet (using /bin/sh):
# Removing system user/group : oncue and oncue
echo "Try deleting system user and group [oncue:oncue]"
if getent passwd | grep -q "^oncue:";
then
    echo "Deleting system user: oncue"
    userdel oncue
fi
if getent group | grep -q "^oncue:" ;
then
    echo "Deleting system group: oncue"
    groupdel oncue
fi

In this case my user and group are never actually installed? The template in the src tree of the plugin indicates that it should create the username and group (as it also tries to delete them)

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 9, 2014

Yeah, this should work.

  • Do you use root as daemonUser?
  • Can you post your target/rpm/SPECS/oncue.spec file?
  • Can you post the output of sbt show rpmPre?

You maybe confused by the output of rpm -qp --scripts. This isn't one script. It's all the different scritplets put into one output. Mind the headings, e.g. postinstall scriptlet (using /bin/sh):

@timperrett
Copy link

Sure @muuki88 , heres the sbt output:

[http] λ show linux:daemonUser
[info] oncue
[http] λ show rpmPre
[info] Some(# Adding system user/group : oncue and oncue
[info] if ! getent group | grep -q "^oncue:" ;
[info] then
[info]     echo "Creating system group: oncue"
[info]     groupadd --system oncue
[info] fi
[info] if ! getent passwd | grep -q "^oncue:";
[info] then
[info]     echo "Creating system user: oncue"
[info]     useradd --gid oncue --no-create-home --system -c 'OnCue http' oncue
[info] fi
[info] )
[http] λ

And the spec file:

λ cat http/target/rpm/SPECS/http.spec
Name: http
Version: 3.2.6bcedba
Release: 0
Summary: OnCue http
License: Copyright OnCue, 2014
Vendor: oncue
Group: oncue
autoprov: yes
autoreq: yes
BuildRoot: <remove-by-tim>/http/target/rpm/buildroot
BuildArch: noarch

%description
http v3.2.6bcedba


%install
if [ -e "$RPM_BUILD_ROOT" ]; then
  mv "<remove-by-tim>/http/target/rpm/tmp-buildroot"/* "$RPM_BUILD_ROOT"
else
  mv "<remove-by-tim>/http/target/rpm/tmp-buildroot" "$RPM_BUILD_ROOT"
fi
%post
#
# Adding oncue to autostart
#
addservice() {
    if hash update-rc.d 2>/dev/null; then
        echo "Adding oncue to autostart using update-rc.d"
        update-rc.d oncue defaults
    elif chkconfig 2>/dev/null; then
        echo "Adding oncue to autostart using chkconfig"
        chkconfig --add oncue
        chkconfig oncue on
    else
        echo "WARNING: Could not put oncue in autostart"
    fi
}

addservice
service oncue start


%preun
# Halting oncue
echo "Shutdown oncue"
service oncue stop


%postun
# Removing system user/group : oncue and oncue
echo "Try deleting system user and group [oncue:oncue]"
if getent passwd | grep -q "^oncue:";
then
    echo "Deleting system user: oncue"
    userdel oncue
fi
if getent group | grep -q "^oncue:" ;
then
    echo "Deleting system group: oncue"
    groupdel oncue
fi

%files
%attr(0755,root,root) /usr/share/oncue/bin/oncue
<removed-by-tim: buch of internal JAR files>
%dir %attr(755,oncue,oncue) /var/log/oncue
%config %attr(755,root,root) /etc/default/oncue
%dir %attr(755,oncue,oncue) /var/run/oncue
%config %attr(0755,root,root) /etc/init.d/oncue
/usr/bin/oncue
/usr/share/oncue/logs

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 9, 2014

Hm, this is confusing. The rpmPre looks good, but the content doesn't make it to the spec. It looks like the setting gets set to None somewhere.

Can you post a minimal build.sbt and your build system config ( os, rpm version ) so I can reproduce the error. The Travis ci tests all work :-\

@timperrett
Copy link

The only keys we're setting are these:

    version in Rpm       := releasingVersion, // so the version is dynamic from version.sbt and git
    normalizedName       := "oncue", // to make the binary location / command fixed
    daemonUser in Linux  := "oncue", // user that the yum install should create
    daemonGroup in Linux := "oncue", // group that the yum install should create
    maintainer           := "OnCue Team",
    packageSummary       := s"OnCue ${name.value}",
    packageDescription   := s"${name.value} v${releasingVersion}",
    rpmVendor            := "oncue",
    rpmLicense           := Some(s"Copyright OnCue, ${Calendar.getInstance.get(Calendar.YEAR)}"),
    rpmGroup             := Some("oncue"),
    rpmBrpJavaRepackJars := true // disables the repacking of JARs (as they are already compressed)

I was building it on my mac, but the same issue is present when building on CentOS

@timperrett
Copy link

PS: I'll work on making a minimal case that reproduces it.

@timperrett
Copy link

@muuki88 - download the reproducing case here: https://dl.dropboxusercontent.com/u/2946026/rpm-scriptlet-bug.zip

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 10, 2014

Thanks a lot for your effort :) I hope to take a close look today as this makes me really curious.

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 10, 2014

Okay, that was faster than I thought:

As a workaround remove the option rpmBrpJavaRepackJars (which sets it to the default false), then the pre script is inserted again.

I will fix this with the next commit here. But not today :(

@timperrett
Copy link

Yeah I figured it would be due to that - I'll hack in the brp macro myself as a workaround but we eagerly await the fix for this

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 10, 2014

Happy to announce the fix :)

@timperrett
Copy link

@muuki88 Looks fixed to me - can we merge it? Thanks for the fast turn around.

@Kreinoee
Copy link

Also works for me now. But should rpmPre setting mayby be a Seq[String] instead of an Option[String]? Currently it only works as long as the build script does not set there own rpmPre string. If the user has need for adding his own rpmPre scriptlet, he will loose the user creation scriptlet. I guess the same goes for the other scriptlets settings.

@muuki88
Copy link
Contributor Author

muuki88 commented Apr 11, 2014

I like the idea of a Seq[String. Still you can add your own settings with a bit more effort like

rpmPre <<= (rpmPre, linuxScriptReplacements) apply { (pre, replacements) =>
      Some(pre.map(_ + "\n").getOrElse("") + "Your new content\n")
}

muuki88 added a commit that referenced this pull request Apr 11, 2014
FIX #214 Making rpm scriptlets overrideable
@muuki88 muuki88 merged commit d2552d2 into master Apr 11, 2014
@muuki88 muuki88 deleted the wip/rpm-template-overrides branch April 11, 2014 09:29
@muuki88
Copy link
Contributor Author

muuki88 commented Apr 11, 2014

I'll merge this for now. @jsuereth can we release RC3?

@Kreinoee
Copy link

Correct, but that is a bit complex (and not very intuiative) compared to just

rpmPre += "some usefull shell command"

Should i create a seperate issue for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants