Skip to content

Commit

Permalink
Merge pull request #711 from fsat/rpm-systemd
Browse files Browse the repository at this point in the history
Ensure systemd works with RPM relocatable packages
  • Loading branch information
muuki88 committed Dec 6, 2015
2 parents db9b0bb + b39af7c commit 45bc15f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
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

0 comments on commit 45bc15f

Please sign in to comment.