From 7dd82d6bb90b1c9f2c657c4eb302627355e235b2 Mon Sep 17 00:00:00 2001 From: wanghai01 Date: Thu, 18 Nov 2021 14:20:03 +0800 Subject: [PATCH] curve-nbd: change auto mount service to systemd --- curve-ansible/clean_nbd.yml | 32 +++++++++++++++++ curve-ansible/client.ini | 2 ++ .../roles/clean/tasks/include/clean_nbd.yml | 23 ++++++++++++ .../roles/install_package/defaults/main.yml | 1 + .../tasks/include/install_curve-nbd.yml | 35 +++++++++++-------- mk-tar.sh | 1 + nbd/nbd-package/DEBIAN/postinst | 6 ++-- nbd/nbd-package/DEBIAN/prerm | 3 +- .../etc/systemd/system/map_curve_disk.service | 22 ++++++++++++ nbd/nbd-package/usr/bin/map_curve_disk.sh | 10 ------ 10 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 curve-ansible/clean_nbd.yml create mode 100644 curve-ansible/roles/clean/tasks/include/clean_nbd.yml create mode 100644 nbd/nbd-package/etc/systemd/system/map_curve_disk.service diff --git a/curve-ansible/clean_nbd.yml b/curve-ansible/clean_nbd.yml new file mode 100644 index 0000000000..cc61b0e077 --- /dev/null +++ b/curve-ansible/clean_nbd.yml @@ -0,0 +1,32 @@ +--- +# +# Copyright (c) 2021 NetEase Inc. +# +# Licensed 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. +# +# The deploy playbook of Curve + +- name: check_ansible_version + tags: + - always + import_playbook: check_ansible_version.yml + +- name: clean nbd + hosts: client + gather_facts: no + any_errors_fatal: true + become: "{{ sudo_or_not | bool }}" + tags: + - prepare + roles: + - { role: clean, module_name: nbd } diff --git a/curve-ansible/client.ini b/curve-ansible/client.ini index 1eae7a11ac..53b2c3c550 100644 --- a/curve-ansible/client.ini +++ b/curve-ansible/client.ini @@ -19,6 +19,8 @@ nebd_server_config_path=/etc/nebd/nebd-server.conf nebd_data_dir=/data/nebd nebd_log_dir=/data/log/nebd curve_sdk_log_dir=/data/log/curve +curvetab_path=/etc/curve +curve_service_path=/etc/systemd/system [mds:vars] mds_port=6666 diff --git a/curve-ansible/roles/clean/tasks/include/clean_nbd.yml b/curve-ansible/roles/clean/tasks/include/clean_nbd.yml new file mode 100644 index 0000000000..f3a9b9a3f9 --- /dev/null +++ b/curve-ansible/roles/clean/tasks/include/clean_nbd.yml @@ -0,0 +1,23 @@ +--- +# +# Copyright (c) 2021 NetEase Inc. +# +# Licensed 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. +# + +- name: clean nbd auto start at boot + block: + - name: disable service + shell: sudo systemctl disable map_curve_disk.service + - name: remove map_curve_disk.service + shell: sudo rm -f {{ curve_service_path }}/map_curve_disk.service && sudo rm -f {{ curvetab_path }}/curvetab diff --git a/curve-ansible/roles/install_package/defaults/main.yml b/curve-ansible/roles/install_package/defaults/main.yml index f0a17f2e8b..ba41ea3ac7 100644 --- a/curve-ansible/roles/install_package/defaults/main.yml +++ b/curve-ansible/roles/install_package/defaults/main.yml @@ -31,6 +31,7 @@ snapshot_clone_server_log_dir: /data/log/curve/snapshotclone local_snapshotcloneserver_package_path: ../curve-snapshotcloneserver local_monitor_package_path: ../../curve-monitor curvetab_path: /etc/curve +curve_service_path: /etc/systemd/system local_snapshotcloneserver_nginx_package_path: ../curve-nginx snapshotcloneserver_nginx_dir: /etc/curve/nginx diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-nbd.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-nbd.yml index 3f4a28f324..989282ce4c 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-nbd.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-nbd.yml @@ -34,28 +34,33 @@ file_mode: 0755 include_tasks: copy_file_to_remote.yml -- name: install curvetab +- name: check curvetab exist + stat: + path: "{{ curvetab_path }}/curvetab" + register: file_status + +- name: install curvetab if not exist vars: remote_dir_name: "{{ curvetab_path }}" - local_file_path: "{{ local_nbd_package_path }}/etc/" + local_file_path: "{{ local_nbd_package_path }}/etc/curvetab" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + when: not file_status.stat.exists + +- name: install map_curve_disk.sh + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_nbd_package_path }}/bin/map_curve_disk.sh" file_mode: 0755 include_tasks: copy_file_to_remote.yml - name: add nbd auto start at boot block: - - name: get distro name - vars: - distro: - include_tasks: common_tasks/get_distro_name.yml - - name: copy map_curve_disk.sh to init.d + - name: install map_curve_disk.service vars: - remote_dir_name: "/etc/init.d" - local_file_path: "{{ local_nbd_package_path }}/bin/map_curve_disk.sh" + remote_dir_name: "{{ curve_service_path }}" + local_file_path: "{{ local_nbd_package_path }}/etc/map_curve_disk.service" file_mode: 0755 include_tasks: copy_file_to_remote.yml - - name: enable on debain ubuntu - shell: sudo update-rc.d map_curve_disk.sh defaults - when: "'Ubuntu' in distro or 'Debian' in distro" - - name: enable on centos - shell: sudo chkconfig --add map_curve_disk.sh && sudo chkconfig map_curve_disk.sh on - when: "'CentOS' in distro" + - name: enable service + shell: sudo systemctl daemon-reload && sudo systemctl enable map_curve_disk.service && sudo systemctl start map_curve_disk.service diff --git a/mk-tar.sh b/mk-tar.sh index d458d1b35e..bebb94e8dc 100644 --- a/mk-tar.sh +++ b/mk-tar.sh @@ -350,6 +350,7 @@ mkdir -p build/nbd-package/etc cp bazel-bin/nbd/src/curve-nbd build/nbd-package/bin cp nbd/nbd-package/usr/bin/map_curve_disk.sh build/nbd-package/bin cp nbd/nbd-package/etc/curve/curvetab build/nbd-package/etc +cp nbd/nbd-package/etc/systemd/system/map_curve_disk.service build/nbd-package/etc #step4 获取git提交版本信息 commit_id=`git show --abbrev-commit HEAD|head -n 1|awk '{print $2}'` diff --git a/nbd/nbd-package/DEBIAN/postinst b/nbd/nbd-package/DEBIAN/postinst index 647feb490f..223c75f32f 100755 --- a/nbd/nbd-package/DEBIAN/postinst +++ b/nbd/nbd-package/DEBIAN/postinst @@ -3,8 +3,10 @@ set -e chmod +x /usr/bin/map_curve_disk.sh -cp /usr/bin/map_curve_disk.sh /etc/init.d -update-rc.d map_curve_disk.sh defaults + +systemctl daemon-reload +systemctl enable map_curve_disk.service +systemctl start map_curve_disk.service CURVETAB=/etc/curve/curvetab CURVETABBAK=/etc/curve/curvetab-bak diff --git a/nbd/nbd-package/DEBIAN/prerm b/nbd/nbd-package/DEBIAN/prerm index 2976220db7..9a3de10008 100755 --- a/nbd/nbd-package/DEBIAN/prerm +++ b/nbd/nbd-package/DEBIAN/prerm @@ -2,7 +2,6 @@ set -e -update-rc.d map_curve_disk.sh remove -rm -f /etc/init.d/map_curve_disk.sh +systemctl disable map_curve_disk.service exit 0 diff --git a/nbd/nbd-package/etc/systemd/system/map_curve_disk.service b/nbd/nbd-package/etc/systemd/system/map_curve_disk.service new file mode 100644 index 0000000000..522ca2a904 --- /dev/null +++ b/nbd/nbd-package/etc/systemd/system/map_curve_disk.service @@ -0,0 +1,22 @@ +[Unit] +Description=curve-nbd auto map service +Before=kubelet.service +After=remote-fs.target +After=network-online.target +After=nebd-daemon.service +Wants=network-online.target + +[Service] +Type=forking +Restart=no +TimeoutSec=5min +IgnoreSIGPIPE=no +KillMode=process +GuessMainPID=no +RemainAfterExit=yes +SuccessExitStatus=5 6 +ExecStart=/usr/bin/map_curve_disk.sh start +ExecStop=/usr/bin/map_curve_disk.sh stop + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/nbd/nbd-package/usr/bin/map_curve_disk.sh b/nbd/nbd-package/usr/bin/map_curve_disk.sh index 82a1f32c0a..0fb75579c3 100755 --- a/nbd/nbd-package/usr/bin/map_curve_disk.sh +++ b/nbd/nbd-package/usr/bin/map_curve_disk.sh @@ -1,15 +1,5 @@ #!/bin/bash -### BEGIN INIT INFO -# Provides: curve-nbd -# Required-Start: $local_fs $remote_fs $network nebd-daemon -# Required-Stop: $local_fs $remote_fs $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: curve-nbd auto map service -# Description: curve-nbd auto map service and associated helpers -### END INIT INFO - # default confpath # file format is:dealflag \t device \t image \t mountpoint(option) # + /dev/nbd0 cbd:pool//curvefile_test_ /test