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

Ensure systemd works with RPM relocatable packages #711

Merged
merged 1 commit into from
Dec 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
startService() {
app_name=$1

app_sys_config="/etc/sysconfig/${app_name}"
[ -e "${app_sys_config}" ] && . "${app_sys_config}"
if [ -n "${PACKAGE_PREFIX}" ] ;
then
default_install_location="${{chdir}}"
actual_install_location="${PACKAGE_PREFIX}/${app_name}"

sed -i "s|$default_install_location|$actual_install_location|g" "/usr/lib/systemd/system/${app_name}.service"
fi

systemctl enable "$app_name.service"
systemctl start "$app_name.service"
}
Expand All @@ -16,6 +26,7 @@ startService() {

stopService() {
app_name=$1

systemctl stop "$app_name.service"
systemctl disable "$app_name.service"
}
Expand All @@ -26,6 +37,7 @@ stopService() {
#
restartService() {
app_name=$1

systemctl daemon-reload
systemctl try-restart "$app_name.service"
}
Expand Down
59 changes: 59 additions & 0 deletions src/sbt-test/rpm/systemd-rpm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,62 @@ TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) =>
out.log.success("Successfully tested systemd start up script")
()
}

TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) =>
val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec")
assert(spec contains
"""
|#
|# Adding service to autostart
|# $1 = service name
|#
|startService() {
| app_name=$1
|
| app_sys_config="/etc/sysconfig/${app_name}"
| [ -e "${app_sys_config}" ] && . "${app_sys_config}"
| if [ -n "${PACKAGE_PREFIX}" ] ;
| then
| default_install_location="/usr/share/rpm-test"
| actual_install_location="${PACKAGE_PREFIX}/${app_name}"
|
| sed -i "s|$default_install_location|$actual_install_location|g" "/usr/lib/systemd/system/${app_name}.service"
| fi
|
| systemctl enable "$app_name.service"
| systemctl start "$app_name.service"
|}
|""".stripMargin, "rpm scriptlet does not systemd service registration and startup")

assert(spec contains
"""
|#
|# Removing service from autostart
|# $1 = service name
|#
|
|stopService() {
| app_name=$1
|
| systemctl stop "$app_name.service"
| systemctl disable "$app_name.service"
|}
|""".stripMargin, "rpm scriptlet does not systemd stop service and disable")

assert(spec contains
"""
|#
|# Restarting the service after package upgrade
|# $1 = service name
|#
|restartService() {
| app_name=$1
|
| systemctl daemon-reload
| systemctl try-restart "$app_name.service"
|}
|""".stripMargin, "rpm scriptlet does not systemd reload during restart")

out.log.success("Successfully tested rpm test file")
()
}
2 changes: 2 additions & 0 deletions src/sbt-test/rpm/systemd-rpm/test
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ $ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm
$ exists usr/lib/systemd/system/rpm-test.service

> checkStartupScript

> checkSpecFile