From a1044e3bd1c5f31d4bff0bce5e1390c4ff5952d7 Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Wed, 4 Sep 2019 08:30:35 +0900 Subject: [PATCH 1/3] dist: move package build script to install.sh Move package build script from .rpm/.deb to single script, install.sh. We need this to support nonroot mode, and also to keep package build script consistent between .rpm/.deb. --- dist/debian/rules.mustache | 23 +------ dist/redhat/scylla-jmx.spec.mustache | 19 +----- install.sh | 94 +++++++++++++++++++++++++++ scripts/create-relocatable-package.py | 1 + 4 files changed, 98 insertions(+), 39 deletions(-) create mode 100755 install.sh diff --git a/dist/debian/rules.mustache b/dist/debian/rules.mustache index b527d7e..a989d99 100755 --- a/dist/debian/rules.mustache +++ b/dist/debian/rules.mustache @@ -1,31 +1,12 @@ #!/usr/bin/make -f -DOC = $(CURDIR)/debian/{{product}}-jmx/opt/scylladb/share/doc/{{product}}-jmx -DEST = $(CURDIR)/debian/{{product}}-jmx/opt/scylladb/jmx -M2_REPO= $(CURDIR)/m2 - override_dh_auto_build: override_dh_auto_clean: override_dh_auto_install: - mkdir -p $(CURDIR)/debian/{{product}}-jmx/etc/default/ && \ - cp $(CURDIR)/dist/common/sysconfig/scylla-jmx \ - $(CURDIR)/debian/{{product}}-jmx/etc/default/ - - mkdir -p $(DOC) && \ - cp $(CURDIR)/*.md $(DOC) - cp $(CURDIR)/NOTICE $(DOC) - - mkdir -p $(DEST) - cp $(CURDIR)/scylla-jmx $(DEST) - cp $(CURDIR)/scylla-jmx-1.0.jar $(DEST) - mkdir $(DEST)/symlinks - ln -sf /usr/bin/java $(DEST)/symlinks/scylla-jmx - - mkdir -p $(CURDIR)/debian/{{product}}-jmx/opt/scylladb/scripts - # Create symlink for /usr/lib/scylla/jmx - ln -sf /opt/scylladb/jmx $(CURDIR)/debian/{{product}}-jmx/opt/scylladb/scripts/ + dh_auto_install + ./install.sh --root "$(CURDIR)/debian/{{product}}-jmx" --disttype debian override_dh_installinit: {{#scylla}} diff --git a/dist/redhat/scylla-jmx.spec.mustache b/dist/redhat/scylla-jmx.spec.mustache index a465f76..cf0270b 100644 --- a/dist/redhat/scylla-jmx.spec.mustache +++ b/dist/redhat/scylla-jmx.spec.mustache @@ -22,26 +22,9 @@ Requires: {{product}}-server java-1.8.0-openjdk-headless %build -MUSTACHE_DIST="\"redhat\": true" -pystache dist/common/systemd/scylla-jmx.service.mustache "{ $MUSTACHE_DIST }" > scylla-jmx.service %install -rm -rf $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ -mkdir -p $RPM_BUILD_ROOT%{_unitdir} -mkdir -p $RPM_BUILD_ROOT/opt/scylladb/ - -install -m644 dist/common/sysconfig/scylla-jmx $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ -install -m644 scylla-jmx.service $RPM_BUILD_ROOT%{_unitdir}/ -install -d -m755 $RPM_BUILD_ROOT/opt/scylladb/ -install -d -m755 $RPM_BUILD_ROOT/opt/scylladb/jmx -install -d -m755 $RPM_BUILD_ROOT/opt/scylladb/jmx/symlinks -install -m644 scylla-jmx-1.0.jar $RPM_BUILD_ROOT/opt/scylladb/jmx/ -install -m755 scylla-jmx $RPM_BUILD_ROOT/opt/scylladb/jmx -ln -sf /usr/bin/java $RPM_BUILD_ROOT/opt/scylladb/jmx/symlinks/scylla-jmx -install -d -m755 $RPM_BUILD_ROOT/opt/scylladb/scripts -# create symlink for /usr/lib/scylla/jmx -ln -sf /opt/scylladb/jmx $RPM_BUILD_ROOT/opt/scylladb/scripts/ +./install.sh --root "$RPM_BUILD_ROOT" --disttype "redhat" %pre /usr/sbin/groupadd scylla 2> /dev/null || : diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..0747db0 --- /dev/null +++ b/install.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# +# Copyright (C) 2019 ScyllaDB +# + +# +# This file is part of Scylla. +# +# Scylla is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Scylla is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Scylla. If not, see . +# + +set -e + +print_usage() { + cat < build/scylla-jmx.service + +install -d -m755 "$retc"/"$sysconfdir" +install -d -m755 "$rusr"/lib/systemd/system +install -d -m755 "$rprefix/scripts" "$rprefix/jmx" "$rprefix/jmx/symlinks" + +install -m644 dist/common/sysconfig/scylla-jmx -Dt "$retc"/"$sysconfdir" +install -m644 build/scylla-jmx.service -Dt "$rusr"/lib/systemd/system + +install -m644 scylla-jmx-1.0.jar "$rprefix/jmx" +install -m755 scylla-jmx "$rprefix/jmx" +ln -sf /usr/bin/java "$rprefix/jmx/symlinks/scylla-jmx" +# create symlink for /usr/lib/scylla/jmx +ln -srf $rprefix/jmx "$rprefix/scripts/" diff --git a/scripts/create-relocatable-package.py b/scripts/create-relocatable-package.py index e64ff30..2a70acf 100755 --- a/scripts/create-relocatable-package.py +++ b/scripts/create-relocatable-package.py @@ -43,6 +43,7 @@ ar.add('build/SCYLLA-RELEASE-FILE', arcname='SCYLLA-RELEASE-FILE') ar.add('build/SCYLLA-VERSION-FILE', arcname='SCYLLA-VERSION-FILE') ar.add('build/SCYLLA-PRODUCT-FILE', arcname='SCYLLA-PRODUCT-FILE') ar.add('dist') +ar.add('install.sh') ar.add('target/scylla-jmx-1.0.jar', arcname='scylla-jmx-1.0.jar') ar.add('scripts/scylla-jmx', arcname='scylla-jmx') ar.add('README.md') From e8355087ead4bded8f31ee8746f36dc097d5f7a1 Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Wed, 4 Sep 2019 08:54:01 +0900 Subject: [PATCH 2/3] dist/common/systemd: untemplataize *.service, use drop-in units instead Since systemd unit can override parameters using drop-in unit, we don't need mustache template for them. Also, drop --disttype option on install.sh since it does not required anymore, introduce --sysconfdir instead for non-redhat distributions. --- ...mx.service.mustache => scylla-jmx.service} | 5 --- dist/debian/rules.mustache | 2 +- dist/redhat/scylla-jmx.spec.mustache | 2 +- install.sh | 36 +++++++++---------- 4 files changed, 18 insertions(+), 27 deletions(-) rename dist/common/systemd/{scylla-jmx.service.mustache => scylla-jmx.service} (83%) diff --git a/dist/common/systemd/scylla-jmx.service.mustache b/dist/common/systemd/scylla-jmx.service similarity index 83% rename from dist/common/systemd/scylla-jmx.service.mustache rename to dist/common/systemd/scylla-jmx.service index 4e1dd6e..e30dc3b 100644 --- a/dist/common/systemd/scylla-jmx.service.mustache +++ b/dist/common/systemd/scylla-jmx.service @@ -5,12 +5,7 @@ After=scylla-server.service [Service] Type=simple -{{#debian}} -EnvironmentFile=/etc/default/scylla-jmx -{{/debian}} -{{#redhat}} EnvironmentFile=/etc/sysconfig/scylla-jmx -{{/redhat}} User=scylla Group=scylla ExecStart=/opt/scylladb/jmx/scylla-jmx $SCYLLA_JMX_PORT $SCYLLA_API_PORT $SCYLLA_API_ADDR $SCYLLA_JMX_ADDR $SCYLLA_JMX_FILE $SCYLLA_JMX_LOCAL $SCYLLA_JMX_REMOTE $SCYLLA_JMX_DEBUG diff --git a/dist/debian/rules.mustache b/dist/debian/rules.mustache index a989d99..a6030f6 100755 --- a/dist/debian/rules.mustache +++ b/dist/debian/rules.mustache @@ -6,7 +6,7 @@ override_dh_auto_clean: override_dh_auto_install: dh_auto_install - ./install.sh --root "$(CURDIR)/debian/{{product}}-jmx" --disttype debian + ./install.sh --root "$(CURDIR)/debian/{{product}}-jmx" --sysconfdir /etc/default override_dh_installinit: {{#scylla}} diff --git a/dist/redhat/scylla-jmx.spec.mustache b/dist/redhat/scylla-jmx.spec.mustache index cf0270b..714ea6b 100644 --- a/dist/redhat/scylla-jmx.spec.mustache +++ b/dist/redhat/scylla-jmx.spec.mustache @@ -24,7 +24,7 @@ Requires: {{product}}-server java-1.8.0-openjdk-headless %build %install -./install.sh --root "$RPM_BUILD_ROOT" --disttype "redhat" +./install.sh --root "$RPM_BUILD_ROOT" %pre /usr/sbin/groupadd scylla 2> /dev/null || : diff --git a/install.sh b/install.sh index 0747db0..80201d7 100755 --- a/install.sh +++ b/install.sh @@ -29,7 +29,7 @@ Usage: install.sh [options] Options: --root /path/to/root alternative install root (default /) --prefix /prefix directory prefix (default /usr) - --disttype [redhat|debian] specify type of distribution (redhat/debian) + --sysconfdir /etc/sysconfig specify sysconfig directory name --help this helpful message EOF exit 1 @@ -37,6 +37,7 @@ EOF root=/ prefix=/opt/scylladb +sysconfdir=/etc/sysconfig while [ $# -gt 0 ]; do case "$1" in @@ -48,8 +49,8 @@ while [ $# -gt 0 ]; do prefix="$2" shift 2 ;; - "--disttype") - disttype="$2" + "--sysconfdir") + sysconfdir="$2" shift 2 ;; "--help") @@ -65,27 +66,22 @@ done rprefix="$root/$prefix" retc="$root/etc" rusr="$root/usr" +rsysconfdir="$root/$sysconfdir" -if [ "$disttype" = "redhat" ]; then - MUSTACHE_DIST="\"redhat\": true" - sysconfdir=sysconfig -elif [ "$disttype" = "debian" ]; then - MUSTACHE_DIST="\"debian\": true" - sysconfdir=default -else - print_usage - exit 1 -fi - -mkdir -p build -pystache dist/common/systemd/scylla-jmx.service.mustache "{ $MUSTACHE_DIST }" > build/scylla-jmx.service - -install -d -m755 "$retc"/"$sysconfdir" +install -d -m755 "$rsysconfdir" install -d -m755 "$rusr"/lib/systemd/system install -d -m755 "$rprefix/scripts" "$rprefix/jmx" "$rprefix/jmx/symlinks" -install -m644 dist/common/sysconfig/scylla-jmx -Dt "$retc"/"$sysconfdir" -install -m644 build/scylla-jmx.service -Dt "$rusr"/lib/systemd/system +install -m644 dist/common/sysconfig/scylla-jmx -Dt "$rsysconfdir" +install -m644 dist/common/systemd/scylla-jmx.service -Dt "$rusr"/lib/systemd/system +if [ "$sysconfdir" != "/etc/sysconfig" ]; then + install -d -m755 "$retc"/systemd/system/scylla-jmx.service.d + cat << EOS > "$retc"/systemd/system/scylla-jmx.service.d/sysconfdir.conf +[Service] +EnvironmentFile= +EnvironmentFile=$sysconfdir/scylla-jmx +EOS +fi install -m644 scylla-jmx-1.0.jar "$rprefix/jmx" install -m755 scylla-jmx "$rprefix/jmx" From 9ef12f46515f7a075b1fb283d19667bf379a7ced Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Wed, 4 Sep 2019 09:33:40 +0900 Subject: [PATCH 3/3] install.sh: add --nonroot mode This implements the way to install Scylla without requires root privilege, not distribution dependent, does not uses package manager. --- install.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 80201d7..46274c0 100755 --- a/install.sh +++ b/install.sh @@ -29,6 +29,7 @@ Usage: install.sh [options] Options: --root /path/to/root alternative install root (default /) --prefix /prefix directory prefix (default /usr) + --nonroot shortcut of '--disttype nonroot' --sysconfdir /etc/sysconfig specify sysconfig directory name --help this helpful message EOF @@ -36,8 +37,8 @@ EOF } root=/ -prefix=/opt/scylladb sysconfdir=/etc/sysconfig +nonroot=false while [ $# -gt 0 ]; do case "$1" in @@ -49,6 +50,10 @@ while [ $# -gt 0 ]; do prefix="$2" shift 2 ;; + "--nonroot") + nonroot=true + shift 1 + ;; "--sysconfdir") sysconfdir="$2" shift 2 @@ -63,24 +68,57 @@ while [ $# -gt 0 ]; do esac done -rprefix="$root/$prefix" -retc="$root/etc" -rusr="$root/usr" -rsysconfdir="$root/$sysconfdir" +if [ -z "$prefix" ]; then + if $nonroot; then + prefix=~/scylladb + else + prefix=/opt/scylladb + fi +fi + +rprefix=$(realpath -m "$root/$prefix") +if ! $nonroot; then + retc="$root/etc" + rsysconfdir="$root/$sysconfdir" + rusr="$root/usr" + rsystemd="$rusr/lib/systemd/system" +else + retc="$rprefix/etc" + rsysconfdir="$rprefix/$sysconfdir" + rsystemd="$retc/systemd" +fi install -d -m755 "$rsysconfdir" -install -d -m755 "$rusr"/lib/systemd/system +install -d -m755 "$rsystemd" install -d -m755 "$rprefix/scripts" "$rprefix/jmx" "$rprefix/jmx/symlinks" install -m644 dist/common/sysconfig/scylla-jmx -Dt "$rsysconfdir" -install -m644 dist/common/systemd/scylla-jmx.service -Dt "$rusr"/lib/systemd/system -if [ "$sysconfdir" != "/etc/sysconfig" ]; then - install -d -m755 "$retc"/systemd/system/scylla-jmx.service.d - cat << EOS > "$retc"/systemd/system/scylla-jmx.service.d/sysconfdir.conf +install -m644 dist/common/systemd/scylla-jmx.service -Dt "$rsystemd" +if ! $nonroot; then + if [ "$sysconfdir" != "/etc/sysconfig" ]; then + install -d -m755 "$retc"/systemd/system/scylla-jmx.service.d + cat << EOS > "$retc"/systemd/system/scylla-jmx.service.d/sysconfdir.conf [Service] EnvironmentFile= EnvironmentFile=$sysconfdir/scylla-jmx EOS + fi +else + install -d -m755 "$retc"/systemd/system/scylla-jmx.service.d + cat << EOS > "$retc"/systemd/system/scylla-jmx.service.d/nonroot.conf +[Service] +EnvironmentFile= +EnvironmentFile=$retc/sysconfig/scylla-jmx +ExecStart= +ExecStart=$rprefix/jmx/scylla-jmx \$SCYLLA_JMX_PORT \$SCYLLA_API_PORT \$SCYLLA_API_ADDR \$SCYLLA_JMX_ADDR \$SCYLLA_JMX_FILE \$SCYLLA_JMX_LOCAL \$SCYLLA_JMX_REMOTE \$SCYLLA_JMX_DEBUG +User= +Group= +EOS + if [ ! -d ~/.config/systemd/user/scylla-jmx.service.d ]; then + mkdir -p ~/.config/systemd/user/scylla-jmx.service.d + fi + ln -srf $rsystemd/scylla-jmx.service ~/.config/systemd/user/ + ln -srf "$retc"/systemd/system/scylla-jmx.service.d/nonroot.conf ~/.config/systemd/user/scylla-jmx.service.d fi install -m644 scylla-jmx-1.0.jar "$rprefix/jmx" @@ -88,3 +126,11 @@ install -m755 scylla-jmx "$rprefix/jmx" ln -sf /usr/bin/java "$rprefix/jmx/symlinks/scylla-jmx" # create symlink for /usr/lib/scylla/jmx ln -srf $rprefix/jmx "$rprefix/scripts/" + +if $nonroot; then + sed -i -e "s#/var/lib/scylla#$rprefix#g" "$rsysconfdir"/scylla-jmx + sed -i -e "s#/etc/scylla#$rprefix/etc/scylla#g" "$rsysconfdir"/scylla-jmx + sed -i -e "s#/opt/scylladb/jmx#$rprefix/jmx#g" "$rsysconfdir"/scylla-jmx + systemctl --user daemon-reload + echo "Scylla-JMX non-root install completed." +fi