From 15a2bf1418b95166c103ff2c45f3ad22964f2d29 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 1 Sep 2023 15:42:21 -0400 Subject: [PATCH] Add custom systemd unit for Zookeeper We're 100% systemd here, and the lack of control/information that the old-school ZK initscript provides is frustrating. Replace it with our own simple unit file. --- roles/pvc/tasks/zookeeper/main.yml | 14 +++++++++-- .../templates/zookeeper/zookeeper.service.j2 | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 roles/pvc/templates/zookeeper/zookeeper.service.j2 diff --git a/roles/pvc/tasks/zookeeper/main.yml b/roles/pvc/tasks/zookeeper/main.yml index 75bc59e..43eb713 100644 --- a/roles/pvc/tasks/zookeeper/main.yml +++ b/roles/pvc/tasks/zookeeper/main.yml @@ -2,7 +2,7 @@ - name: install zookeeper packages apt: name: - - zookeeperd + - zookeeper - zookeeper-bin state: latest @@ -18,7 +18,17 @@ - zoo.cfg notify: restart zookeeper -- name: start but disable services +- name: install systemd unit file + template: + src: zookeeper/zookeeper.service.j2 + dest: /etc/systemd/system/zookeeper.service + register: systemd + +- name: reload systemd to apply changes + command: systemctl daemon-reload + when: systemd.changed + +- name: start but disable services (managed by PVC) service: name: "{{ item }}" state: started diff --git a/roles/pvc/templates/zookeeper/zookeeper.service.j2 b/roles/pvc/templates/zookeeper/zookeeper.service.j2 new file mode 100644 index 0000000..7dd2143 --- /dev/null +++ b/roles/pvc/templates/zookeeper/zookeeper.service.j2 @@ -0,0 +1,23 @@ +# Zookeeper unit - replaces zookeeperd package/initscript +# {{ ansible_managed }} + +[Unit] +Description = Zookeeper centralized coordination service +After = remote-fs.target network.target +AssertPathExists = /var/lib/zookeeper + +[Service] +Type = simple +User = zookeeper +Group = zookeeper +EnvironmentFile = -/etc/zookeeper/conf/environment +EnvironmentFile = -/etc/default/zookeeper +ExecStart = /usr/bin/java \ + -cp $CLASSPATH \ + $JAVA_OPTS \ + -Dzookeeper.log.dir=${ZOO_LOG_DIR} \ + -Dzookeeper.root.logger=${ZOO_LOG4J_PROP} \ + $ZOOMAIN $ZOOCFG + +[Install] +WantedBy = multi-user.target