This is an automated email from the ASF dual-hosted git repository.

iwasakims pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bigtop.git


The following commit(s) were added to refs/heads/master by this push:
     new ab0c1e171 BIGTOP-4197. Provide systemd service unit files(RPM): 
ZooKeeper (#1295)
ab0c1e171 is described below

commit ab0c1e171e7468f844e90624d0e6b87c92916dd8
Author: masatana <[email protected]>
AuthorDate: Mon Oct 28 19:50:56 2024 +0900

    BIGTOP-4197. Provide systemd service unit files(RPM): ZooKeeper (#1295)
---
 .../modules/hadoop_zookeeper/manifests/init.pp     |   1 +
 .../src/common/zookeeper/install_zookeeper.sh      |   2 +-
 .../src/common/zookeeper/zookeeper-rest.svc        |   4 +-
 .../src/common/zookeeper/zookeeper-server.service  |  38 ++++++
 .../src/common/zookeeper/zookeeper-server.sh       |   6 +-
 .../src/common/zookeeper/zookeeper-server.sh.suse  | 142 ---------------------
 .../src/rpm/zookeeper/SPECS/zookeeper.spec         |  32 +++--
 7 files changed, 60 insertions(+), 165 deletions(-)

diff --git a/bigtop-deploy/puppet/modules/hadoop_zookeeper/manifests/init.pp 
b/bigtop-deploy/puppet/modules/hadoop_zookeeper/manifests/init.pp
index 1051dc7de..ff52c88fa 100644
--- a/bigtop-deploy/puppet/modules/hadoop_zookeeper/manifests/init.pp
+++ b/bigtop-deploy/puppet/modules/hadoop_zookeeper/manifests/init.pp
@@ -82,6 +82,7 @@ class hadoop_zookeeper (
                      File["/var/lib/zookeeper/myid"] ],
       hasrestart => true,
       hasstatus => true,
+      provider => systemd,
     }
 
     file { "/etc/zookeeper/conf/zoo.cfg":
diff --git a/bigtop-packages/src/common/zookeeper/install_zookeeper.sh 
b/bigtop-packages/src/common/zookeeper/install_zookeeper.sh
index c3e1b5bde..84a2f95a7 100755
--- a/bigtop-packages/src/common/zookeeper/install_zookeeper.sh
+++ b/bigtop-packages/src/common/zookeeper/install_zookeeper.sh
@@ -187,7 +187,7 @@ for pairs in zkServer.sh/zookeeper-server 
zkServer-initialize.sh/zookeeper-serve
 # Autodetect JAVA_HOME if not defined
 . /usr/lib/bigtop-utils/bigtop-detect-javahome
 
-export ZOOPIDFILE=\${ZOOPIDFILE:-/var/run/zookeeper/zookeeper_server.pid}
+export ZOOPIDFILE=\${ZOOPIDFILE:-/run/zookeeper/zookeeper_server.pid}
 export ZOOKEEPER_HOME=\${ZOOKEEPER_HOME:-${LIB_DIR}}
 export ZOOKEEPER_CONF=\${ZOOKEEPER_CONF:-/etc/zookeeper/conf}
 export ZOOCFGDIR=\${ZOOCFGDIR:-\$ZOOKEEPER_CONF}
diff --git a/bigtop-packages/src/common/zookeeper/zookeeper-rest.svc 
b/bigtop-packages/src/common/zookeeper/zookeeper-rest.svc
index aa2905d8d..31aaf6ad1 100644
--- a/bigtop-packages/src/common/zookeeper/zookeeper-rest.svc
+++ b/bigtop-packages/src/common/zookeeper/zookeeper-rest.svc
@@ -16,10 +16,10 @@
 DAEMON="zookeeper-rest"
 DESC="ZooKeeper REST Server"
 SVC_USER="${ZOOKEEPER_USER:-zookeeper}"
-WORKING_DIR="/var/run/zookeeper"
+WORKING_DIR="/run/zookeeper"
 DAEMON_FLAGS=""
 CONF_DIR="/etc/zookeeper/conf/rest"
-PIDFILE="/var/run/zookeeper/zookeeper-rest-$SVC_USER.pid"
+PIDFILE="/run/zookeeper/zookeeper-rest-$SVC_USER.pid"
 
 generate_start() {
 
diff --git a/bigtop-packages/src/common/zookeeper/zookeeper-server.service 
b/bigtop-packages/src/common/zookeeper/zookeeper-server.service
new file mode 100644
index 000000000..106ae7ae3
--- /dev/null
+++ b/bigtop-packages/src/common/zookeeper/zookeeper-server.service
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[Unit]
+Documentation=https://zookeeper.apache.org/
+Description=ZooKeeper is a centralized service for maintaining configuration 
information, naming, providing distributed synchronization, and providing group 
services.
+Before=multi-user.target
+Before=graphical.target
+After=network-online.target
+After=nss-lookup.target
+Wants=network-online.target
+
+[Service]
+User=zookeeper
+Group=zookeeper
+Type=forking
+Restart=no
+TimeoutSec=5min
+IgnoreSIGPIPE=no
+KillMode=process
+GuessMainPID=no
+RemainAfterExit=no
+PIDFile=/run/zookeeper/zookeeper_server.pid
+SuccessExitStatus=5 6
+ExecStart=/usr/bin/zookeeper-server start
+ExecStop=/usr/bin/zookeeper-server stop
diff --git a/bigtop-packages/src/common/zookeeper/zookeeper-server.sh 
b/bigtop-packages/src/common/zookeeper/zookeeper-server.sh
index a59afe91c..4117a6687 100755
--- a/bigtop-packages/src/common/zookeeper/zookeeper-server.sh
+++ b/bigtop-packages/src/common/zookeeper/zookeeper-server.sh
@@ -18,7 +18,7 @@
 # chkconfig: 2345 80 20
 # description: Summary: ZooKeeper is a centralized service for maintaining 
configuration information, naming, providing distributed synchronization, and 
providing group services. All of these kinds of services are used in some form 
or another by distributed applications. Each time they are implemented there is 
a lot of work that goes into fixing the bugs and race conditions that are 
inevitable. Because of the difficulty of implementing these kinds of services, 
applications initially usua [...]
 # processname: java
-# pidfile: /var/run/zookeeper/zookeeper_server.pid
+# pidfile: /run/zookeeper/zookeeper_server.pid
 ### BEGIN INIT INFO
 # Provides:          zookeeper-server
 # Required-Start:    $network $local_fs
@@ -41,8 +41,8 @@ DAEMON_SCRIPT="/usr/bin/zookeeper-server"
 
 NAME=zookeeper-server
 DESC="ZooKeeper daemon"
-PID_FILE=/var/run/zookeeper/zookeeper_server.pid
-install -d -m 0755 -o zookeeper -g zookeeper /var/run/zookeeper/
+PID_FILE=/run/zookeeper/zookeeper_server.pid
+install -d -m 0755 -o zookeeper -g zookeeper /run/zookeeper/
 
 DODTIME=3
 
diff --git a/bigtop-packages/src/common/zookeeper/zookeeper-server.sh.suse 
b/bigtop-packages/src/common/zookeeper/zookeeper-server.sh.suse
deleted file mode 100644
index 30271455b..000000000
--- a/bigtop-packages/src/common/zookeeper/zookeeper-server.sh.suse
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/bin/bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Starts Zookeeper server
-#
-# chkconfig: 345 80 20
-# description: Summary: ZooKeeper is a centralized service for maintaining 
configuration information, naming, providing distributed synchronization, and 
providing group services. All of these kinds of services are used in some form 
or another by distributed applications. Each time they are implemented there is 
a lot of work that goes into fixing the bugs and race conditions that are 
inevitable. Because of the difficulty of implementing these kinds of services, 
applications initially usua [...]
-#
-### BEGIN INIT INFO
-# Provides:          zookeeper-server
-# Required-Start:    $network $local_fs
-# Should-Start:      $named
-# Required-Stop:     $syslog $remote_fs
-# Should-Stop:
-# Default-Start:     3 4 5
-# Default-Stop:      0 1 2 6
-# Short-Description: ZooKeeper is a centralized service for maintaining 
configuration information, naming, providing distributed synchronization, and 
providing group services.
-### END INIT INFO
-
-. /lib/lsb/init-functions
-
-# Autodetect JAVA_HOME if not defined
-. /usr/lib/bigtop-utils/bigtop-detect-javahome
-
-. /etc/default/zookeeper
-
-STATUS_RUNNING=0
-STATUS_DEAD=1
-STATUS_DEAD_AND_LOCK=2
-STATUS_NOT_RUNNING=3
-
-ERROR_PROGRAM_NOT_INSTALLED=5
-
-RETVAL=0
-EXEC_PATH="/usr/bin/zookeeper-server"
-NAME=zookeeper-server
-DESC="$NAME"
-PIDFILE=/var/run/zookeeper/zookeeper_server.pid
-LOCKFILE="/var/lock/subsys/zookeeper"
-USER=zookeeper
-
-install -d -m 0755 -o zookeeper -g zookeeper /var/run/zookeeper/
-
-
-start() {
-  [ -x $exec ] || exit $ERROR_PROGRAM_NOT_INSTALLED
-  log_success_msg "Starting $DESC: "
-  start_daemon -u $USER $EXEC_PATH start
-  RETVAL=$?
-  echo
-  [ $RETVAL -eq 0 ] && touch $LOCKFILE
-  return $RETVAL
-}
-
-stop() {
-  log_success_msg "Stopping $DESC: "
-  start_daemon -u $USER $EXEC_PATH stop
-  RETVAL=$?
-  sleep 5
-  echo
-  [ $RETVAL -eq 0 ] && rm -f $LOCKFILE $PIDFILE
-}
-
-restart() {
-  stop
-  start
-}
-
-checkstatus(){
-  pidofproc -p $PIDFILE java > /dev/null
-  status=$?
-
-  case "$status" in
-    $STATUS_RUNNING)
-      log_success_msg "$NAME is running"
-      ;;
-    $STATUS_DEAD)
-      log_failure_msg "$NAME is dead and pid file exists"
-      ;;
-    $STATUS_DEAD_AND_LOCK)
-      log_failure_msg "$NAME is dead and lock file exists"
-      ;;
-    $STATUS_NOT_RUNNING)
-      log_failure_msg "$NAME is not running"
-      ;;
-    *)
-      log_failure_msg "$NAME status is unknown"
-      ;;
-  esac
-  return $status
-}
-
-condrestart(){
-  [ -e $LOCKFILE ] && restart || :
-}
-
-case "$1" in
-  start)
-    start
-    ;;
-  stop)
-    stop
-    ;;
-  status)
-    checkstatus
-    ;;
-  restart)
-    restart
-    ;;
-  condrestart|try-restart)
-    condrestart
-    ;;
-  init)
-    checkstatus
-    if [ "$?" = "$STATUS_RUNNING" ] ; then
-      echo "Error: $DESC is running. Stop it first." >&2
-      exit 1
-    else
-      shift
-      runuser -s /bin/bash $USER -c "zookeeper-server-initialize $*"
-    fi
-    ;;
-  *)
-    echo $"Usage: $0 {start|stop|status|restart|try-restart|condrestart|init}"
-    exit 1
-esac
-
-exit $RETVAL
diff --git a/bigtop-packages/src/rpm/zookeeper/SPECS/zookeeper.spec 
b/bigtop-packages/src/rpm/zookeeper/SPECS/zookeeper.spec
index 2865a2d89..5d923899c 100644
--- a/bigtop-packages/src/rpm/zookeeper/SPECS/zookeeper.spec
+++ b/bigtop-packages/src/rpm/zookeeper/SPECS/zookeeper.spec
@@ -29,7 +29,7 @@
 
 # No prefix directory
 %define np_var_log_zookeeper /var/log/%{zookeeper_name}
-%define np_var_run_zookeeper /var/run/%{zookeeper_name}
+%define np_run_zookeeper /run/%{zookeeper_name}
 %define np_etc_zookeeper /etc/%{zookeeper_name}
 
 %define svc_zookeeper %{zookeeper_name}-server
@@ -84,15 +84,14 @@ License: ASL 2.0
 Source0: apache-%{zookeeper_name}-%{zookeeper_base_version}.tar.gz
 Source1: do-component-build
 Source2: install_zookeeper.sh
-Source3: zookeeper-server.sh
-Source4: zookeeper-server.sh.suse
 Source5: zookeeper.1
 Source6: zoo.cfg
 Source7: zookeeper.default
 Source8: init.d.tmpl
 Source9: zookeeper-rest.svc
+Source10: zookeeper-server.service
 #BIGTOP_PATCH_FILES
-BuildRequires: autoconf, automake, cppunit-devel
+BuildRequires: autoconf, automake, cppunit-devel, systemd
 Requires(pre): coreutils, /usr/sbin/groupadd, /usr/sbin/useradd
 Requires(post): %{alternatives_dep}
 Requires(preun): %{alternatives_dep}
@@ -178,26 +177,20 @@ bash %{SOURCE2} \
           --system-include-dir=%{include_dir} \
           --system-lib-dir=%{lib_dir}
 
-%if  %{?suse_version:1}0
-orig_init_file=%{SOURCE4}
-%else
-orig_init_file=%{SOURCE3}
-%endif
-
-%__install -d -m 0755 $RPM_BUILD_ROOT/%{initd_dir}/
-init_file=$RPM_BUILD_ROOT/%{initd_dir}/%{svc_zookeeper}
-%__cp $orig_init_file $init_file
-chmod 755 $init_file
 
+    
 # Install Zookeeper REST server init script
 init_file=$RPM_BUILD_ROOT/%{initd_dir}/zookeeper-rest
 bash $RPM_SOURCE_DIR/init.d.tmpl $RPM_SOURCE_DIR/zookeeper-rest.svc rpm 
$init_file
 
+# Install ZooKeeper Server systemd service file
+%__install -D -m 0644 %{SOURCE10} 
$RPM_BUILD_ROOT/%{_unitdir}/zookeeper-server.service
+
 %pre
 getent group zookeeper >/dev/null || groupadd -r zookeeper
 getent passwd zookeeper > /dev/null || useradd -c "ZooKeeper" -s /sbin/nologin 
-g zookeeper -r -d %{var_lib_zookeeper} zookeeper 2> /dev/null || :
 
-%__install -d -o zookeeper -g zookeeper -m 0755 %{np_var_run_zookeeper}
+%__install -d -o zookeeper -g zookeeper -m 0755 %{np_run_zookeeper}
 %__install -d -o zookeeper -g zookeeper -m 0755 %{np_var_log_zookeeper}
 
 # Manage configuration symlink
@@ -205,24 +198,29 @@ getent passwd zookeeper > /dev/null || useradd -c 
"ZooKeeper" -s /sbin/nologin -
 %{alternatives_cmd} --install %{np_etc_zookeeper}/conf %{zookeeper_name}-conf 
%{etc_zookeeper_conf_dist} 30
 %__install -d -o zookeeper -g zookeeper -m 0755 %{var_lib_zookeeper}
 
+
 %preun
 if [ "$1" = 0 ]; then
         %{alternatives_cmd} --remove %{zookeeper_name}-conf 
%{etc_zookeeper_conf_dist} || :
 fi
 
+
 %post server
-       chkconfig --add %{svc_zookeeper}
+chkconfig --add %{svc_zookeeper}
+%systemd_post zookeeper-server.service
 
 %preun server
 if [ $1 = 0 ] ; then
        service %{svc_zookeeper} stop > /dev/null 2>&1
        chkconfig --del %{svc_zookeeper}
 fi
+%systemd_preun zookeeper-server.service
 
 %postun server
 if [ $1 -ge 1 ]; then
         service %{svc_zookeeper} condrestart > /dev/null 2>&1
 fi
+%systemd_postun zookeeper-server.service
 
 %post rest
        chkconfig --add %{svc_zookeeper_rest}
@@ -255,7 +253,7 @@ fi
 %{man_dir}/man1/zookeeper.1.*
 
 %files server
-%attr(0755,root,root) %{initd_dir}/%{svc_zookeeper}
+%attr(0644,root,root) %{_unitdir}/zookeeper-server.service
 
 %files rest
 %attr(0755,root,root) %{initd_dir}/%{svc_zookeeper_rest}

Reply via email to