diff --git a/curve-ansible/clean_curve_sdk.yml b/curve-ansible/clean_curve_sdk.yml index 0fbabb0c5b..63458fabf3 100644 --- a/curve-ansible/clean_curve_sdk.yml +++ b/curve-ansible/clean_curve_sdk.yml @@ -25,6 +25,7 @@ hosts: client gather_facts: no any_errors_fatal: true + become: "{{ sudo_or_not | bool }}" tags: - prepare roles: diff --git a/curve-ansible/clean_nebd.yml b/curve-ansible/clean_nebd.yml index 7f2e1872f3..006b6ec847 100644 --- a/curve-ansible/clean_nebd.yml +++ b/curve-ansible/clean_nebd.yml @@ -28,6 +28,7 @@ hosts: client gather_facts: no any_errors_fatal: true + become: "{{ sudo_or_not | bool }}" tags: - prepare roles: diff --git a/curve-ansible/common_tasks/check_chunkserver.yml b/curve-ansible/common_tasks/check_chunkserver.yml index c1ef500a1a..d1ad7d78fd 100644 --- a/curve-ansible/common_tasks/check_chunkserver.yml +++ b/curve-ansible/common_tasks/check_chunkserver.yml @@ -103,10 +103,13 @@ that: - firmware_version.stdout|version_compare('24.3.0-0050', '>=') +- name: get chunkserver number + include_tasks: "get_chunkserver_number.yml" + - name: check the disk schedule algorithm shell: cat /sys/block/sd*/queue/scheduler | grep "\[noop\]" | wc -l register: result - failed_when: result.stdout | int != chunkserver_num + failed_when: result.stdout | int < chunkserver_num | int - name: check if the disk cache closed shell: sudo /sbin/hdparm -W /dev/sd* | grep "write-caching" diff --git a/curve-ansible/common_tasks/get_chunkserver_number.yml b/curve-ansible/common_tasks/get_chunkserver_number.yml new file mode 100644 index 0000000000..c09296dbd2 --- /dev/null +++ b/curve-ansible/common_tasks/get_chunkserver_number.yml @@ -0,0 +1,30 @@ +--- +# +# 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. +# +# Get chunkserver number + +- name: get chunkserver number not get disk automatically + set_fact: + chunkserver_num: "{{ disk_list | length }}" + when: not auto_get_disk_list | bool + +- name: get chunkserver number get disk automatically + block: + - shell: echo '{{ get_disk_list_cmd }} | wc -l' + register: result + - set_fact: + chunkserver_num: "{{ result.stdout }}" + when: auto_get_disk_list | bool diff --git a/curve-ansible/common_tasks/install_with_yum_apt.yml b/curve-ansible/common_tasks/install_with_yum_apt.yml index 008c85033b..266438496f 100644 --- a/curve-ansible/common_tasks/install_with_yum_apt.yml +++ b/curve-ansible/common_tasks/install_with_yum_apt.yml @@ -40,7 +40,15 @@ register: result - name: install lib with yum shell: sudo yum -y install {{ yum_lib_name }} + register: install_result when: result.rc != 0 + - name: install latest repository + shell: sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm + register: repository + when: install_result.rc != 0 + - name: retry install + shell: sudo yum -y install {{ yum_lib_name }} + when: install_result.rc != 0 and repository.rc != 0 when: - "'CentOS' in distro" diff --git a/curve-ansible/roles/clean/tasks/include/clean_chunkserver_retain_chunkfilepool.yml b/curve-ansible/roles/clean/tasks/include/clean_chunkserver_retain_chunkfilepool.yml index 33121f32b6..8a1a8d9d23 100644 --- a/curve-ansible/roles/clean/tasks/include/clean_chunkserver_retain_chunkfilepool.yml +++ b/curve-ansible/roles/clean/tasks/include/clean_chunkserver_retain_chunkfilepool.yml @@ -15,6 +15,9 @@ # limitations under the License. # +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: clean chunkserver dat vars: end_seq: "{{ chunkserver_num | int - 1}}" diff --git a/curve-ansible/roles/clean/tasks/include/clean_chunkserver_totally.yml b/curve-ansible/roles/clean/tasks/include/clean_chunkserver_totally.yml index 51ebaabeff..4417f62fcc 100644 --- a/curve-ansible/roles/clean/tasks/include/clean_chunkserver_totally.yml +++ b/curve-ansible/roles/clean/tasks/include/clean_chunkserver_totally.yml @@ -15,6 +15,9 @@ # limitations under the License. # +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: clean data under data dir vars: end_seq: "{{ chunkserver_num | int - 1}}" diff --git a/curve-ansible/roles/format_chunkserver/tasks/include/prepare_chunkserver_without_disk_format.yml b/curve-ansible/roles/format_chunkserver/tasks/include/prepare_chunkserver_without_disk_format.yml index d240e3ce76..3fedb950d1 100644 --- a/curve-ansible/roles/format_chunkserver/tasks/include/prepare_chunkserver_without_disk_format.yml +++ b/curve-ansible/roles/format_chunkserver/tasks/include/prepare_chunkserver_without_disk_format.yml @@ -18,6 +18,9 @@ - name: clear data dir shell: sudo rm -rf {{ chunkserver_data_dir }}/chunkserver* +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: create data dir and log dir for each chunkserver vars: end_seq: "{{ chunkserver_num | int - 1}}" diff --git a/curve-ansible/roles/generate_config/tasks/include/generate_config_with_template.yml b/curve-ansible/roles/generate_config/tasks/include/generate_config_with_template.yml index cc3de13213..5ef2f7ffa0 100644 --- a/curve-ansible/roles/generate_config/tasks/include/generate_config_with_template.yml +++ b/curve-ansible/roles/generate_config/tasks/include/generate_config_with_template.yml @@ -47,9 +47,13 @@ - name: set backup true set_fact: backup: true + - name: check config file exist + stat: + path: "{{ conf_path }}" + register: file_status - name: backup config file shell: sudo cp {{ conf_path }} {{ conf_path }}.bak - when: backup is defined + when: backup is defined and file_status.stat.exists - name: mv config file shell: sudo mv /tmp/{{ template_name }} {{ conf_path }} - name: diff two files diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-chunkserver.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-chunkserver.yml index f704722c1a..c0f5e497fe 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-chunkserver.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-chunkserver.yml @@ -15,43 +15,45 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install bzip2 - vars: - apt_lib_name: bzip2 - yum_lib_name: bzip2 - include_tasks: common_tasks/install_with_yum_apt.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: install jemalloc - vars: - lib_name: jemalloc - download_url: "{{ jemalloc_download_url }}" - include_tasks: install_jemalloc.yml - -- name: install psmisc - vars: - apt_lib_name: psmisc - yum_lib_name: psmisc - include_tasks: common_tasks/install_with_yum_apt.yml - when: chunkserver_format_disk | bool - -- name: install chunkserver bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_chunkserver_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml +- name: install package via tar + block: + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev + vars: + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install bzip2 + vars: + apt_lib_name: bzip2 + yum_lib_name: bzip2 + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install jemalloc + vars: + lib_name: jemalloc + download_url: "{{ jemalloc_download_url }}" + include_tasks: install_jemalloc.yml + - name: install psmisc + vars: + apt_lib_name: psmisc + yum_lib_name: psmisc + include_tasks: common_tasks/install_with_yum_apt.yml + when: chunkserver_format_disk | bool + - name: install chunkserver bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_chunkserver_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + when: not install_with_deb | bool - name: generate chunkserver_ctl.sh vars: diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-mds.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-mds.yml index c8dcb3a1c1..0a9882d7ad 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-mds.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-mds.yml @@ -15,46 +15,47 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libuuid - vars: - apt_lib_name: libuuid1 - yum_lib_name: libuuid - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libuuid-dev - vars: - apt_lib_name: uuid-dev - yum_lib_name: libuuid-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install daemon - include_tasks: install_daemon.yml - -- name: install mds bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_mds_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: install mds lib - vars: - remote_dir_name: "{{ curve_lib_dir }}" - local_file_path: "{{ local_mds_package_path }}/lib/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool + +- name: install package via tar + block: + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev + vars: + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libuuid + vars: + apt_lib_name: libuuid1 + yum_lib_name: libuuid + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libuuid-dev + vars: + apt_lib_name: uuid-dev + yum_lib_name: libuuid-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install daemon + include_tasks: install_daemon.yml + - name: install mds bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_mds_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: install mds lib + vars: + remote_dir_name: "{{ curve_lib_dir }}" + local_file_path: "{{ local_mds_package_path }}/lib/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + when: not install_with_deb | bool - name: generate mds-daemon.sh template: src=mds-daemon.sh.j2 dest={{ deploy_dir }}/mds-daemon.sh mode=0755 diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-monitor.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-monitor.yml index 9f51f331fa..4c29fa39d7 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-monitor.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-monitor.yml @@ -15,27 +15,27 @@ # limitations under the License. # -- name: pull prom/prometheus:latest - shell: sudo docker image pull prom/prometheus:latest +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: pull grafana/grafana:latest - shell: sudo docker image pull grafana/grafana:latest - -- name: promoon/reporter:latest - shell: sudo docker image pull promoon/reporter:latest - -- name: install jq - vars: - apt_lib_name: jq - yum_lib_name: jq - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install monitor work space - vars: - remote_dir_name: "{{ monitor_work_dir }}" - local_file_path: "{{ local_monitor_package_path }}/" - file_mode: 0777 - include_tasks: copy_file_to_remote.yml - -- name: generate curve-monitor.sh - template: src=curve-monitor.sh.j2 dest={{ deploy_dir }}/curve-monitor.sh mode=0755 +- name: install package via tar + block: + - name: pull prom/prometheus:latest + shell: sudo docker image pull prom/prometheus:latest + - name: pull grafana/grafana:latest + shell: sudo docker image pull grafana/grafana:latest + - name: promoon/reporter:latest + shell: sudo docker image pull promoon/reporter:latest + - name: install jq + vars: + apt_lib_name: jq + yum_lib_name: jq + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install monitor work space + vars: + remote_dir_name: "{{ monitor_work_dir }}" + local_file_path: "{{ local_monitor_package_path }}/" + file_mode: 0777 + include_tasks: copy_file_to_remote.yml + when: not install_with_deb | bool 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 72cafc2213..b302887f0b 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 @@ -15,59 +15,60 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libnl - vars: - apt_lib_name: libnl-3-dev - yum_lib_name: libnl3 - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libnl-dev - vars: - apt_lib_name: libnl-genl-3-dev - yum_lib_name: libnl3-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install nbd bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_nbd_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: install curvetab - vars: - remote_dir_name: "{{ curvetab_path }}" - local_file_path: "{{ local_nbd_package_path }}/etc/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: add nbd auto start at boot +- name: install package via tar block: - - name: get distro name + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev vars: - distro: - include_tasks: common_tasks/get_distro_name.yml - - name: copy map_curve_disk.sh to init.d + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libnl + vars: + apt_lib_name: libnl-3-dev + yum_lib_name: libnl3 + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libnl-dev + vars: + apt_lib_name: libnl-genl-3-dev + yum_lib_name: libnl3-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install nbd bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_nbd_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: install curvetab vars: - remote_dir_name: "/etc/init.d" - local_file_path: "{{ local_nbd_package_path }}/bin/map_curve_disk.sh" + remote_dir_name: "{{ curvetab_path }}" + local_file_path: "{{ local_nbd_package_path }}/etc/" 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: 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 + vars: + remote_dir_name: "/etc/init.d" + local_file_path: "{{ local_nbd_package_path }}/bin/map_curve_disk.sh" + 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" + when: not install_with_deb | bool diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-sdk.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-sdk.yml index 71b1a64f0d..0930096c54 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-sdk.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-sdk.yml @@ -15,47 +15,48 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install curve-sdk bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_curve_sdk_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: install curve-sdk lib - vars: - remote_dir_name: "{{ curve_lib_dir }}" - local_file_path: "{{ local_curve_sdk_package_path }}/lib/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml - -- name: install curve-sdk include - vars: - remote_dir_name: "{{ curve_include_dir }}" - local_file_path: "{{ local_curve_sdk_package_path }}/include/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml - -- name: install curve-sdk curvefs - vars: - remote_dir_name: "{{ curvefs_dir }}" - local_file_path: "{{ local_curve_sdk_package_path }}/curvefs/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml - -- name: create log dir - vars: - dir_name: "{{ curve_sdk_log_dir }}" - include_tasks: common_tasks/create_dir.yml +- name: install package via tar + block: + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev + vars: + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install curve-sdk bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_curve_sdk_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: install curve-sdk lib + vars: + remote_dir_name: "{{ curve_lib_dir }}" + local_file_path: "{{ local_curve_sdk_package_path }}/lib/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + - name: install curve-sdk include + vars: + remote_dir_name: "{{ curve_include_dir }}" + local_file_path: "{{ local_curve_sdk_package_path }}/include/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + - name: install curve-sdk curvefs + vars: + remote_dir_name: "{{ curvefs_dir }}" + local_file_path: "{{ local_curve_sdk_package_path }}/curvefs/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + - name: create log dir + vars: + dir_name: "{{ curve_sdk_log_dir }}" + include_tasks: common_tasks/create_dir.yml + when: not install_with_deb | bool diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver-nginx.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver-nginx.yml index b327e5015c..53322f0841 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver-nginx.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver-nginx.yml @@ -15,9 +15,14 @@ # limitations under the License. # -- name: install snapshotcloneserver_nginx +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool + +- name: install snapshotcloneserver_nginx via tar vars: remote_dir_name: "{{ snapshotcloneserver_nginx_dir }}" local_file_path: "{{ local_snapshotcloneserver_nginx_package_path }}/" file_mode: 0644 - include_tasks: copy_file_to_remote.yml \ No newline at end of file + include_tasks: copy_file_to_remote.yml + when: not install_with_deb | bool \ No newline at end of file diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver.yml index 02c7c5dec3..5963635298 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-snapshotcloneserver.yml @@ -15,46 +15,47 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libuuid - vars: - apt_lib_name: libuuid1 - yum_lib_name: libuuid - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install libuuid-dev - vars: - apt_lib_name: uuid-dev - yum_lib_name: libuuid-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install daemon - include_tasks: install_daemon.yml - -- name: install snapshotcloneserver bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_snapshotcloneserver_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: install snapshotcloneserver lib - vars: - remote_dir_name: "{{ curve_lib_dir}}" - local_file_path: "{{ local_snapshotcloneserver_package_path }}/lib/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool + +- name: install package via tar + block: + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev + vars: + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libuuid + vars: + apt_lib_name: libuuid1 + yum_lib_name: libuuid + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libuuid-dev + vars: + apt_lib_name: uuid-dev + yum_lib_name: libuuid-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install daemon + include_tasks: install_daemon.yml + - name: install snapshotcloneserver bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_snapshotcloneserver_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: install snapshotcloneserver lib + vars: + remote_dir_name: "{{ curve_lib_dir}}" + local_file_path: "{{ local_snapshotcloneserver_package_path }}/lib/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + when: not install_with_deb | bool - name: generate snapshot-daemon.sh - template: src=snapshot-daemon.sh.j2 dest={{ deploy_dir }}/snapshot-daemon.sh mode=0755 \ No newline at end of file + template: src=snapshot-daemon.sh.j2 dest={{ deploy_dir }}/snapshot-daemon.sh mode=0755 diff --git a/curve-ansible/roles/install_package/tasks/include/install_curve-tools.yml b/curve-ansible/roles/install_package/tasks/include/install_curve-tools.yml index 94e520df21..27ae5a42b5 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_curve-tools.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_curve-tools.yml @@ -15,18 +15,23 @@ # limitations under the License. # -- name: install tool bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_tool_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: pip install requests - ignore_errors: true - shell: sudo pip install requests - register: pip_requests_res - -- name: pip2 install requests - shell: sudo pip2 install requests - when: pip_requests_res.failed +- name: install package via tar + block: + - name: install tool bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_tool_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: pip install requests + ignore_errors: true + shell: sudo pip install requests + register: pip_requests_res + - name: pip2 install requests + shell: sudo pip2 install requests + when: pip_requests_res.failed + when: not install_with_deb | bool diff --git a/curve-ansible/roles/install_package/tasks/include/install_nebd.yml b/curve-ansible/roles/install_package/tasks/include/install_nebd.yml index 21ecaf7b72..973c3cd2f4 100644 --- a/curve-ansible/roles/install_package/tasks/include/install_nebd.yml +++ b/curve-ansible/roles/install_package/tasks/include/install_nebd.yml @@ -15,92 +15,87 @@ # limitations under the License. # -- name: install libunwind - vars: - apt_lib_name: libunwind8 - yum_lib_name: libunwind - include_tasks: common_tasks/install_with_yum_apt.yml +- name: install package via deb + include_tasks: "install_deb_package.yml" + when: install_with_deb | bool -- name: install libunwind-dev - vars: - apt_lib_name: libunwind8-dev - yum_lib_name: libunwind-devel - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install bzip2 - vars: - apt_lib_name: bzip2 - yum_lib_name: bzip2 - include_tasks: common_tasks/install_with_yum_apt.yml - -- name: install jemalloc - vars: - lib_name: jemalloc - download_url: "{{ jemalloc_download_url }}" - include_tasks: install_jemalloc.yml - -- name: install daemon - include_tasks: install_daemon.yml - -- name: prepare date dir - vars: - dir_name: "{{ nebd_data_dir }}" - include_tasks: common_tasks/create_dir.yml - -- name: prepare log dir - vars: - dir_name: "{{ nebd_log_dir }}/{{ item }}" - include_tasks: common_tasks/create_dir.yml - with_items: - - client - - server - -- name: prepare lock dir - vars: - dir_name: "{{ nebd_data_dir }}/lock" - include_tasks: common_tasks/create_dir.yml - -- name: install nebd bin - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "{{ local_nebd_package_path }}/bin/" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: install nebd lib - vars: - remote_dir_name: "{{ curve_lib_dir }}/nebd" - local_file_path: "{{ local_nebd_package_path }}/lib/" - file_mode: 0644 - include_tasks: copy_file_to_remote.yml - -- name: generate nebd-daemon - vars: - jemalloc_path: "{{ lib_install_prefix }}/lib/libjemalloc.so.1" - local_action: template src=nebd-daemon.j2 dest=/tmp/nebd-daemon mode=0755 - -- name: copy nebd-daemon - vars: - remote_dir_name: "{{ curve_bin_dir }}" - local_file_path: "/tmp/nebd-daemon" - file_mode: 0755 - include_tasks: copy_file_to_remote.yml - -- name: add nebd auto start at boot +- name: install package via tar block: - - name: get distro name + - name: install libunwind + vars: + apt_lib_name: libunwind8 + yum_lib_name: libunwind + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install libunwind-dev + vars: + apt_lib_name: libunwind8-dev + yum_lib_name: libunwind-devel + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install bzip2 + vars: + apt_lib_name: bzip2 + yum_lib_name: bzip2 + include_tasks: common_tasks/install_with_yum_apt.yml + - name: install jemalloc + vars: + lib_name: jemalloc + download_url: "{{ jemalloc_download_url }}" + include_tasks: install_jemalloc.yml + - name: install daemon + include_tasks: install_daemon.yml + - name: prepare date dir + vars: + dir_name: "{{ nebd_data_dir }}" + include_tasks: common_tasks/create_dir.yml + - name: prepare log dir + vars: + dir_name: "{{ nebd_log_dir }}/{{ item }}" + include_tasks: common_tasks/create_dir.yml + with_items: + - client + - server + - name: prepare lock dir + vars: + dir_name: "{{ nebd_data_dir }}/lock" + include_tasks: common_tasks/create_dir.yml + - name: install nebd bin + vars: + remote_dir_name: "{{ curve_bin_dir }}" + local_file_path: "{{ local_nebd_package_path }}/bin/" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: install nebd lib + vars: + remote_dir_name: "{{ curve_lib_dir }}/nebd" + local_file_path: "{{ local_nebd_package_path }}/lib/" + file_mode: 0644 + include_tasks: copy_file_to_remote.yml + - name: generate nebd-daemon vars: - distro: - include_tasks: common_tasks/get_distro_name.yml - - name: copy nebd-daemon to init.d + jemalloc_path: "{{ lib_install_prefix }}/lib/libjemalloc.so.1" + local_action: template src=nebd-daemon.j2 dest=/tmp/nebd-daemon mode=0755 + - name: copy nebd-daemon vars: - remote_dir_name: "/etc/init.d" + remote_dir_name: "{{ curve_bin_dir }}" local_file_path: "/tmp/nebd-daemon" file_mode: 0755 include_tasks: copy_file_to_remote.yml - - name: enable on debain ubuntu - shell: sudo update-rc.d nebd-daemon defaults - when: "'Ubuntu' in distro or 'Debian' in distro" - - name: enable on centos - shell: sudo chkconfig --add nebd-daemon && sudo chkconfig nebd-daemon on - when: "'CentOS' in distro" + - name: add nebd auto start at boot + block: + - name: get distro name + vars: + distro: + include_tasks: common_tasks/get_distro_name.yml + - name: copy nebd-daemon to init.d + vars: + remote_dir_name: "/etc/init.d" + local_file_path: "/tmp/nebd-daemon" + file_mode: 0755 + include_tasks: copy_file_to_remote.yml + - name: enable on debain ubuntu + shell: sudo update-rc.d nebd-daemon defaults + when: "'Ubuntu' in distro or 'Debian' in distro" + - name: enable on centos + shell: sudo chkconfig --add nebd-daemon && sudo chkconfig nebd-daemon on + when: "'CentOS' in distro" + when: not install_with_deb | bool diff --git a/curve-ansible/roles/install_package/tasks/main.yml b/curve-ansible/roles/install_package/tasks/main.yml index 66d9b5efbf..dbe4a9bd8a 100644 --- a/curve-ansible/roles/install_package/tasks/main.yml +++ b/curve-ansible/roles/install_package/tasks/main.yml @@ -18,10 +18,5 @@ - name: set curve_lib_dir include_tasks: "include/set_curve_lib_dir.yml" -- name: install package with deb - include_tasks: "include/install_deb_package.yml" - when: install_with_deb | bool - -- name: install package without deb +- name: install package include_tasks: "include/install_{{ package_name }}.yml" - when: not install_with_deb | bool diff --git a/curve-ansible/roles/install_package/templates/chunkserver_deploy.sh.j2 b/curve-ansible/roles/install_package/templates/chunkserver_deploy.sh.j2 index 9c100c2fa0..0a8a9806e3 100644 --- a/curve-ansible/roles/install_package/templates/chunkserver_deploy.sh.j2 +++ b/curve-ansible/roles/install_package/templates/chunkserver_deploy.sh.j2 @@ -14,7 +14,7 @@ function do_confirm { fi } -{% if not auto_get_disk_list %} +{% if not auto_get_disk_list | bool %} {% set dlist=[] -%} {% for disk in disk_list -%} {% set _ = dlist.append("%s" % (disk)) -%} diff --git a/curve-ansible/roles/install_package/templates/curve-monitor.sh.j2 b/curve-ansible/roles/install_package/templates/curve-monitor.sh.j2 deleted file mode 100644 index 900394fbe0..0000000000 --- a/curve-ansible/roles/install_package/templates/curve-monitor.sh.j2 +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh - -#sh update_dashboard.sh -#echo "update dashboards success!" - -WORKDIR={{ monitor_work_dir }} - -if [ ! -d $WORKDIR ]; then - echo "${WORKDIR} not exists" - exit 1 -fi - -cd $WORKDIR -chmod -R 777 prometheus -chmod -R 777 grafana - -start() { - echo "==========start===========" - - echo "" > monitor.log - - stdbuf -oL python target_json.py >> monitor.log 2>&1 & - echo "start prometheus targets service success!" - - docker-compose up >> monitor.log 2>&1 & - echo "start metric system success!" -} - -stop() { - echo "===========stop============" - - docker-compose down - - ID=`(ps -ef | grep "target_json.py"| grep -v "grep") | awk '{print $2}'` - for id in $ID - do - kill -9 $id - echo "killed $id" - done -} - -restart() { - stop - echo "sleeping........." - sleep 3 - start -} - -case "$1" in - 'start') - start - ;; - 'stop') - stop - ;; - 'status') - status - ;; - 'restart') - restart - ;; - *) - echo "usage: $0 {start|stop|restart}" - exit 1 - ;; - esac diff --git a/curve-ansible/roles/prepare_software_env/tasks/main.yml b/curve-ansible/roles/prepare_software_env/tasks/main.yml index 2c9b45f43c..e793d8ca0d 100644 --- a/curve-ansible/roles/prepare_software_env/tasks/main.yml +++ b/curve-ansible/roles/prepare_software_env/tasks/main.yml @@ -15,6 +15,12 @@ # limitations under the License. # +- name: install gcc + vars: + apt_lib_name: gcc + yum_lib_name: gcc + include_tasks: common_tasks/install_with_yum_apt.yml + - name: get gcc version shell: gcc -dumpversion register: gcc_version diff --git a/curve-ansible/roles/restart_service/tasks/include/restart_chunkserver.yml b/curve-ansible/roles/restart_service/tasks/include/restart_chunkserver.yml index 8e8e921405..4ff4665af6 100644 --- a/curve-ansible/roles/restart_service/tasks/include/restart_chunkserver.yml +++ b/curve-ansible/roles/restart_service/tasks/include/restart_chunkserver.yml @@ -15,6 +15,9 @@ # limitations under the License. # +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: Determine need restart or not include_tasks: append_need_restart_cs_list.yml with_sequence: start=0 end={{ chunkserver_num | int - 1}} diff --git a/curve-ansible/roles/start_service/tasks/include/start_chunkserver.yml b/curve-ansible/roles/start_service/tasks/include/start_chunkserver.yml index 69512d54e9..25fecb2337 100644 --- a/curve-ansible/roles/start_service/tasks/include/start_chunkserver.yml +++ b/curve-ansible/roles/start_service/tasks/include/start_chunkserver.yml @@ -32,6 +32,9 @@ debug: var: start_chunkserver_res.stdout_lines +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: wait until chunkserver is up vars: end_seq: "{{ chunkserver_num | int - 1}}" diff --git a/curve-ansible/roles/start_service/tasks/include/start_monitor.yml b/curve-ansible/roles/start_service/tasks/include/start_monitor.yml index b7bf88e3f2..ab8fbe7298 100644 --- a/curve-ansible/roles/start_service/tasks/include/start_monitor.yml +++ b/curve-ansible/roles/start_service/tasks/include/start_monitor.yml @@ -16,7 +16,7 @@ # - name: start monitor - shell: chdir={{ deploy_dir }} sudo ./curve-monitor.sh start + shell: chdir={{ monitor_work_dir }} sudo ./curve-monitor.sh start - name: wait until prometheus is up vars: diff --git a/curve-ansible/roles/stop_service/tasks/include/stop_chunkserver.yml b/curve-ansible/roles/stop_service/tasks/include/stop_chunkserver.yml index 5a26e8563f..9706f433c8 100644 --- a/curve-ansible/roles/stop_service/tasks/include/stop_chunkserver.yml +++ b/curve-ansible/roles/stop_service/tasks/include/stop_chunkserver.yml @@ -24,6 +24,9 @@ ignore_errors: true shell: chdir={{ deploy_dir }} {{ sudo }} ./chunkserver_ctl.sh stop all +- name: get chunkserver number + include_tasks: "common_tasks/get_chunkserver_number.yml" + - name: wait until chunkserver is down vars: end_seq: "{{ chunkserver_num | int - 1}}" diff --git a/curve-ansible/server.ini b/curve-ansible/server.ini index 0351f31585..4588d37c6c 100644 --- a/curve-ansible/server.ini +++ b/curve-ansible/server.ini @@ -82,8 +82,6 @@ auto_get_disk_list=True get_disk_list_cmd="lsscsi |grep ATA|awk '{print $7}'|awk -F/ '{print $3}'" chunk_alloc_percent=85 wal_segment_alloc_percent=10 -# 每台机器上的chunkserver的数量 -chunkserver_num=3 chunkserver_need_sudo=True chunkserver_conf_path=/etc/curve/chunkserver.conf chunkserver_data_dir=/home/curve/data diff --git a/curve-ansible/stop_nebd_server.yml b/curve-ansible/stop_nebd_server.yml index c293c601ee..a976930a81 100644 --- a/curve-ansible/stop_nebd_server.yml +++ b/curve-ansible/stop_nebd_server.yml @@ -25,5 +25,6 @@ hosts: client gather_facts: no any_errors_fatal: true + become: "{{ sudo_or_not | bool }}" roles: - { role: stop_service, service_name: nebd, command_need_sudo: "{{ nebd_need_sudo | bool }}" } diff --git a/curve-chunkserver/home/nbs/chunkserver_deploy.sh b/curve-chunkserver/home/nbs/chunkserver_deploy.sh deleted file mode 100644 index 546ba960ff..0000000000 --- a/curve-chunkserver/home/nbs/chunkserver_deploy.sh +++ /dev/null @@ -1,313 +0,0 @@ -#!/bin/bash - -# -# Copyright (c) 2020 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. -# - -#confirm提示,防止误操作 -function do_confirm { - echo "This deployment script will format the disk and delete all the data." - echo "Please confirm that you want to do this action!" - echo "If you confirm it, please input:" - echo "Yes, I do!" - read tips - if [ "$tips" != "Yes, I do!" ] - then - echo "Exit without actions" - exit - fi -} - -function deploy_prep { -#清理/etc/fstab残留信息 - grep curvefs /etc/fstab - if [ $? -eq 0 ] - then - sed -i '/curvefs/d' /etc/fstab - sed -i '/\/data\/chunkserver/d' /etc/fstab - fi -#通过lsscsi的输出过滤出curve使用的数据盘,将数据盘挂载的目录都卸载掉,为下一步格式化磁盘做准备 - for i in `lsscsi |grep ATA|awk '{print $7}'|awk -F"/" '{print $3}'` - do - mntdir=`lsblk|grep $i|awk '{print $7}'` - if [ -z $mntdir ] - then - continue - fi - echo "umount $mntdir" - fuser -kv $mntdir - umount $mntdir - if [ $? -ne 0 ] - then - echo "umount $mntdir failed" - exit - fi - done -} - -#记录磁盘的盘符信息和磁盘的wwn信息,将信息持久化到diskinfo文件 -DATA_DIR=/data -declare -A disk_map -diskinfo=./diskinfo -function record_diskinfo { - for i in `lsblk -O|grep ATA|awk '{print $1}'` - do - wwn=`lsblk -o NAME,WWN|grep $i|awk '{print $2}'` - disk_map["$i"]=$wwn - done - - echo "disk_map length: " ${#disk_map[@]} - - [ -e $diskinfo ] && rm -r diskinfo - - for m in ${!disk_map[@]} - do - echo "Disk:"$m" <==> ""wwn:"${disk_map[$m]} >> $diskinfo - done -} - -#根据磁盘数量创建数据目录和日志目录,目前的数据目录格式统一是/data/chunkserver+num,日志目录在/data/log/chunkserver+num -function chunk_dir_prep { - if [ -d ${DATA_DIR} ] - then - rm -rf ${DATA_DIR} - if [ $? -ne 0 ] - then - echo "rm $DATA_DIR failed" - exit - fi - fi - mkdir -p ${DATA_DIR} - echo $((${#disk_map[@]}-1)) - for i in `seq 0 $((${#disk_map[@]}-1))` - do - mkdir -p ${DATA_DIR}/chunkserver$i - mkdir -p ${DATA_DIR}/log/chunkserver$i - done -} - -#格式化磁盘文件系统 -function disk_format { - for disk in ${!disk_map[@]} - do - echo $disk - mkfs.ext4 -F /dev/$disk 2>&1 > /dev/null & - done -} - -#将创建好的数据目录按照顺序挂载到格式化好的磁盘上,并记录挂载信息到mount.info -function mount_dir { - while [ 1 ] - do - ps -efl|grep mkfs|grep -v grep 2>&1 >/dev/null - if [ $? -eq 0 ] - then - echo "doing mkfs, sleep 5s and retry." - sleep 5 - continue - fi - break - done - - j=0 - for i in `cat $diskinfo |awk '{print $1}'|awk -F":" '{print $2}'` - do - mount /dev/$i $DATA_DIR/chunkserver$j - if [ $? -ne 0 ] - then - echo "mount $i failed" - exit - fi - ((j++)); - done - - lsblk > ./mount.info -} - -#持久化挂载信息到fstab文件,防止系统重启后丢失 -function fstab_record { - grep curvefs /etc/fstab - if [ $? -ne 0 ] - then - echo "#curvefs" >> /etc/fstab - for i in `lsblk|grep chunkserver|awk '{print $1}' | grep -Eo 'sd.*|vd.*'` - do - echo "UUID=`ls -l /dev/disk/by-uuid/|grep $i|awk '{print $9}'` `lsblk|grep $i|awk '{print $7}'` ext4 rw,errors=remount-ro 0 0" >> /etc/fstab - done - fi -} - -#将当前的uuid持久化到磁盘上做备份,防止系统重启后uuid发生变化 -function meta_record { - grep curvefs /etc/fstab - if [ $? -eq 0 ] - then - for i in `cat /etc/fstab | grep "/data/chunkserver" | awk '{print $1 $2}' | awk -F '=' '{print $2}'` - do - uuid=`echo $i | awk -F / '{print $1}'` - uuidmd5=`echo -n $uuid | md5sum | cut -d ' ' -f1` - datadir=`echo $i | awk -F / '{print "/" $2 "/" $3}'` - touch $datadir/disk.meta - echo "uuid=$uuid" > $datadir/disk.meta - echo "uuidmd5=$uuidmd5" >> $datadir/disk.meta - done - fi -} - -#初始化chunkfile pool -function chunkfile_pool_prep { -ret=`lsblk|grep chunkserver|wc -l` -for i in `seq 0 $((${ret}-1))` -do - curve-format -allocatePercent=85 \ - -filePoolDir=/data/chunkserver$i/chunkfilepool \ - -filePoolMetaPath=/data/chunkserver$i/chunkfilepool.meta \ - -fileSystemPath=/data/chunkserver$i/chunkfilepool & -done -wait -} - -function deploy_one_walfile_pool { - curve-format -allocatePercent=10 \ - -filePoolDir=/data/chunkserver$1/walfilepool \ - -filePoolMetaPath=/data/chunkserver$1/walfilepool.meta \ - -fileSize=8388608 \ - -fileSystemPath=/data/chunkserver$1/walfilepool & -} - -function release_disk_reserved_space { - disks=`lsscsi |grep ATA|awk '{print $7}'|awk -F/ '{print $3}'` - for disk in ${disks} - do - sudo tune2fs -m 0 /dev/$disk - done -} - -# format walfile pool -function walfile_pool_prep { - ret=`lsblk|grep chunkserver|wc -l` - for i in `seq 0 $((${ret}-1))` - do - deploy_one_walfile_pool $i - done - wait -} - -function usage { - echo "HELP: this tool will prepare the chunkserver running env." - echo " you can deploy all the disks by setting all" - echo " or deploy one disk by setting the diskname" - echo "Example:" - echo " ./chunkserver_deploy2.sh all" - echo " ./chunkserver_deploy2.sh /dev/sd{id} /data/chunkserver{id}" - exit -} - -function deploy_all { - deploy_prep; - record_diskinfo; - chunk_dir_prep; - disk_format; - mount_dir; - fstab_record; - meta_record; - chunkfile_pool_prep; - release_disk_reserved_space; -} - -function deploy_one { - local diskname=$1 - local dirname=$2 - #磁盘不存在 - lsscsi|grep -w $diskname - if [ $? -ne 0 ] - then - echo "$diskname is not exist!" - exit - fi - #目录不存在 - if [ ! -d $dirname ] - then - echo "$dirname is not exist!" - exit - fi - #磁盘正在挂载使用 - mount | grep -w $diskname - if [ $? -eq 0 ] - then - echo "$diskname is being used" - exit - fi - #目录正在挂载使用 - mount | grep -w $dirname - if [ $? -eq 0 ] - then - echo "$dirname is being used" - exit - fi - #排除一下系统盘(目前都是通过ATA字段区分,后续硬件环境变动可能需要修改) - lsscsi|grep -v ATA|grep -w $diskname - if [ $? -eq 0 ] - then - echo "$diskname is system bootdisk, you can not use it!" - exit - fi - # remove mount from fstab - line_num=`grep -n $dirname /etc/fstab | cut -f1 -d:` - if [ -n "$line_num" ] - then - sed -i ''${line_num}'d' /etc/fstab - fi - # mkfs - mkfs.ext4 -F $diskname 2>&1 > /dev/null & - while [ 1 ] - do - ps -efl|grep mkfs|grep -v grep 2>&1 >/dev/null - if [ $? -eq 0 ] - then - echo "doing mkfs, sleep 5s and retry." - sleep 5 - continue - fi - break - done - record_diskinfo; - mount $diskname $dirname - lsblk > ./mount.info - #更新fstab - short_diskname=`echo $diskname|awk -F"/" '{print $3}'` - ls -l /dev/disk/by-uuid|grep -w $short_diskname - if [ $? -ne 0 ] - then - echo "$short_diskname is not exist" - exit - fi - uuid=`ls -l /dev/disk/by-uuid/|grep -w ${short_diskname}|awk '{print $9}'` - echo "UUID=$uuid $dirname ext4 rw,errors=remount-ro 0 0" >> /etc/fstab - # 将uuid及其md5写到diskmeta中 - uuidmd5=`echo -n $uuid | md5sum | cut -d ' ' -f1` - touch $dirname/disk.meta - echo "uuid=$uuid" > $dirname/disk.meta - echo "uuidmd5=$uuidmd5" >> $dirname/disk.meta - #格式化chunkfile pool - curve-format -allocatePercent=85 \ - -filePoolDir=$dirname/chunkfilepool \ - -filePoolMetaPath=$dirname/chunkfilepool.meta \ - -fileSystemPath=$dirname/chunkfilepool & - wait - # release disk reserved space - sudo tune2fs -m 0 $diskname - exit -} diff --git a/curve-chunkserver/home/nbs/disk_uuid_repair.py b/curve-chunkserver/home/nbs/disk_uuid_repair.py deleted file mode 100644 index eb48728e2e..0000000000 --- a/curve-chunkserver/home/nbs/disk_uuid_repair.py +++ /dev/null @@ -1,225 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- - -# -# Copyright (c) 2020 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. -# - -# 检测磁盘上disk.meta中记录的uuid与当前磁盘的实际uuid是否相符合 -# 如果不符合, 更新为当前的uuid - -import os -import hashlib -import sys -import subprocess - -def __get_umount_disk_list(): - # 获取需要挂载的设备 - cmd = "lsblk -O|grep ATA|awk '{print $1}'" - out_msg = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - devlist = out_msg.splitlines() - - # 查看当前设备的挂载状况 - umount = [] - for dev in devlist: - cmd = "lsblk|grep " + dev + "|awk '{print $7}'" - out_msg = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - - if len(out_msg.replace('\n', '')) == 0: - umount.append(dev) - return umount - -def __uninit(): - try: - cmd = "grep curvefs /etc/fstab" - subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - return False - except subprocess.CalledProcessError: - return True - -def __analyse_uuid(kv): - uuid = "" - uuidkv = kv[0].split("=") - if len(uuidkv) != 2: - print("uuid[%s] record format error." % kv[0]) - return "" - else: - uuid = uuidkv[1].replace("\n", "") - - uuidmd5kv = kv[1].split("=") - if len(uuidmd5kv) != 2: - print("uuidmd5[%s] record format error." % kv[1]) - return "" - else: - uuidmd5 = uuidmd5kv[1].replace("\n", "") - # 校验 - if (hashlib.md5(uuid).hexdigest() != uuidmd5): - print("uuid[%s] not match uuidmd5[%s]" % (uuid, uuidmd5)) - return "" - return uuid - -def __get_recorduuid(disk): - uuid = "" - # 将磁盘挂载到临时目录 - cmd = "mkdir -p /data/tmp; mount " + disk + " /data/tmp" - retCode = subprocess.call(cmd, shell=True) - if retCode != 0: - print("Get record uuid in %s fail." % disk) - return False, uuid - - # 挂载成功,获取记录的uuid - try: - cmd = "cat /data/tmp/disk.meta" - out_msg = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - - kv = out_msg.splitlines() - if len(kv) != 2: - print("File disk.meta in %s error." % disk) - else: - uuid = __analyse_uuid(kv) - if len(uuid) == 0: - print("Get uuid from disk.meta in %s fail." % disk) - except subprocess.CalledProcessError as e: - print("Get file disk.meta from %s fail, reason: %s." % (disk, e)) - - # 卸载磁盘 - cmd = "umount " + disk + "; rm -fr /data/tmp" - retCode = subprocess.call(cmd, shell=True) - if retCode != 0: - print("call [%s] occurr error." % cmd) - return False, uuid - - return True, uuid - -def __get_actualuuid(disk): - uuid = "" - try: - cmd = "ls -l /dev/disk/by-uuid/|grep " + disk + "|awk '{print $9}'" - uuid = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - print("Get actual uuid of %s fail, reason: %s." % (disk, e)) - - return uuid - -def __cmp_recorduuid_with_actual(umountDisk): - recordList = {} - actualList = {} - for disk in umountDisk: - # 获取当前disk上记录的uuid - diskFullName = "/dev/" + disk - opRes, recorduuid = __get_recorduuid(diskFullName) - if opRes != True or len(recorduuid) == 0: - return False, recordList, actualList - - # 获取disk的实际uuid - actualuuid = __get_actualuuid(disk).replace("\n", "") - - # 比较记录的和实际的是否相同 - if actualuuid != recorduuid: - recordList[disk] = recorduuid - actualList[disk] = actualuuid - else: - return False, recordList, actualList - - return True, recordList, actualList - -def __mount_with_atual_uuid(diskPath, record, actual): - print("%s uuid change from [%s] to [%s]." % (diskPath, record, actual)) - # 从/etc/fstab中获取对应的挂载目录 - mntdir = "" - try: - cmd = "grep " + record + " /etc/fstab | awk -F \" \" '{print $2}'" - mntdir = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT).replace("\n", "") - except subprocess.CalledProcessError as e: - print("Get mount dir for %s fail. error: %s." % (diskPath, e)) - return False - - # 将actual挂载到相应的目录下 - cmd = "mount " + diskPath + " " + mntdir - retCode = subprocess.call(cmd, shell=True) - if retCode !=0: - print("exec [%s] fail." % cmd) - return False - print("mount %s to %s success." % (diskPath, mntdir)) - - replaceCmd = "sed -i \"s/" + record + "/" + actual + "/g\"" - # 将新的uuid写入到fstab - cmd = "cp /etc/fstab /etc/fstab.bak;" + replaceCmd + " /etc/fstab > /dev/null" - retCode = subprocess.call(cmd, shell=True) - if retCode !=0: - print("exec [%s] fail." % cmd) - return False - print("modify actual uuid to /etc/fstab for disk %s success." % diskPath) - - # 将新的uuid写入到diskmeta - fileFullName = mntdir + "/disk.meta" - filebakName = fileFullName + ".bak" - cpcmd = "cp " + fileFullName + " " + filebakName - uuidcmd = "echo uuid=" + actual + " > " + fileFullName - uuidmd5cmd = "echo uuidmd5=" + hashlib.md5(actual).hexdigest() + " >> " + fileFullName - cmd = cpcmd + ";" + uuidcmd + ";" + uuidmd5cmd - retCode = subprocess.call(cmd, shell=True) - if retCode !=0: - print("exec [%s] fail." % cmd) - return False - print("modify actual uuid to %s success." % fileFullName) - - return True - - -def __handle_inconsistent(umountDisk, record, actual): - for disk in umountDisk: - if disk not in record: - print("record uuid and actual uuid of %s is same, please check other reason" % disk) - continue - # 按照actual uuid做挂载 - res = __mount_with_atual_uuid("/dev/" + disk, record[disk], actual[disk]) - if res: - continue - else: - return False - return True - -if __name__ == "__main__": - # 查看未挂载成功的磁盘设备列表 - umountDisk = __get_umount_disk_list() - if len(umountDisk) == 0: - print("All disk mount success.") - exit(0) - - # 查看是否之前已经挂载过 - if __uninit(): - print("Please init env with chunkserver_ctl.sh first.") - exit(0) - - # 查看当前未挂载成功的磁盘设备记录的uuid和实际uuid - cmpRes, record, actual = __cmp_recorduuid_with_actual(umountDisk) - if cmpRes == False: - print("Compare record uuid with actual uuid fail.") - exit(-1) - elif len(record) == 0: - print("Record uuid with actual uuid all consistent.") - exit(0) - - # 将不一致的磁盘按照当前的uuid重新挂载 - if __handle_inconsistent(umountDisk, record, actual): - print("fix uuid-changed disk[%s] success." % umountDisk) - exit(0) - else: - print("fxi uuid-changed disk[%s] fail." % umountDisk) - exit(-1) - - - diff --git a/curve-mds/home/nbs/etcd-daemon.sh b/curve-mds/home/nbs/etcd-daemon.sh deleted file mode 100755 index 4314171c93..0000000000 --- a/curve-mds/home/nbs/etcd-daemon.sh +++ /dev/null @@ -1,205 +0,0 @@ -#!/bin/bash - -# -# Copyright (c) 2020 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. -# - -# 默认配置文件 -confPath=/etc/curve/etcd/etcd.conf.yml - -# 日志文件目录 -logDir=/data/log/curve/etcd - -# 日志文件路径 -logPath=${logDir}/etcd.log - -# pidfile -pidFile=${HOME}/etcd.pid - -# daemon log -daemonLog=${logDir}/daemon-etcd.log - -# 启动etcd -function start_etcd() { - # 创建logDir - mkdir -p ${logDir} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Create etcd log dir failed: ${logDir}" - exit 1 - fi - - # 检查logPath是否有写权限 - if [ ! -w ${logDir} ] - then - echo "Write permission denied: ${logDir}" - exit 1 - fi - - # 检查logPath是否可写或者是否能够创建 - touch ${logPath} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create etcd logfile: ${logPath}" - exit - fi - - # 检查daemonLog是否可写或者是否能够创建 - touch ${daemonLog} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create daemon logfile: ${daemonLog}" - exit - fi - - # 检查daemon - if ! type daemon &> /dev/null - then - echo "No daemon installed" - exit - fi - - # 检查是否安装etcd - if [ -z `command -v etcd` ] - then - echo "No etcd installed" - exit - fi - - # 检查配置文件 - if [ ! -f ${confPath} ] - then - echo "Not found confFile, Path is ${confPath}" - exit - fi - - # 判断是否已经通过daemon启动了etcd - daemon --name etcd --pidfile ${pidFile} --running - if [ $? -eq 0 ] - then - echo "Already started etcd by daemon" - exit - fi - - # pidfile不存在 或 daemon进程不存在 - # 启动daemon,切换路径,并启动etcd - - - daemon --name etcd --core \ - --respawn --attempts 100 --delay 10 \ - --pidfile ${pidFile} \ - --errlog ${daemonLog} \ - --output ${logPath} \ - --unsafe \ - -- etcd --config-file ${confPath} -} - -# 停止daemon进程和etcd -function stop_etcd() { - # 判断是否已经通过daemon启动了etcd - daemon --name etcd --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start etcd by daemon" - exit 0 - fi - - daemon --name etcd --pidfile ${pidFile} --stop - if [ $? -ne 0 ] - then - echo "stop may not success!" - else - echo "etcd exit success!" - echo "daemon exit success!" - fi -} - -# restart -function restart_etcd() { - # 判断是否已经通过daemon启动了etcd - daemon --name etcd --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start etcd by daemon" - exit 1 - fi - - daemon --name etcd --pidfile ${pidFile} --restart - if [ $? -ne 0 ] - then - echo "Restart failed" - fi -} - -# 使用方式 -function usage() { - echo "Usage:" - echo " etcd-daemon start -- start deamon process and watch on etcd process" - echo " [-c|--confPath path] etcd conf path" - echo " [-l|--logPath path] etcd log path" - echo " etcd-daemon stop -- stop daemon process and etcd" - echo " etcd-daemon restart -- restart etcd" - echo "Examples:" - echo " etcd-daemon start -c /etcd/etcd.conf.yml -l ${HOME}/etcd.log" -} - -# 检查参数启动参数,最少1个 -if [ $# -lt 1 ] -then - usage - exit -fi - -case $1 in -"start") - shift # pass first argument - - # 解析参数 - while [[ $# -gt 1 ]] - do - key=$1 - - case $key in - -c|--confPath) - confPath=`realpath $2` - shift # pass key - shift # pass value - ;; - -l|--logPath) - logPath=`realpath $2` - shift # pass key - shift # pass value - ;; - *) - usage - exit - ;; - esac - done - - start_etcd - ;; -"stop") - # 停止daemon和etcd进程 - stop_etcd - ;; -"restart") - # 重启etcd - restart_etcd - ;; -*) - usage - ;; -esac diff --git a/curve-mds/home/nbs/mds-daemon.sh b/curve-mds/home/nbs/mds-daemon.sh deleted file mode 100755 index 5fd8115d21..0000000000 --- a/curve-mds/home/nbs/mds-daemon.sh +++ /dev/null @@ -1,287 +0,0 @@ -#!/bin/bash - -# -# Copyright (c) 2020 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. -# - -# curve-mds路径 -curveBin=/usr/bin/curve-mds - -# 默认配置文件 -confPath=/etc/curve/mds.conf - -# 日志文件路径 -logPath=/data/log/curve/mds - -# mdsAddr -mdsAddr= - -# pidfile -pidFile=${HOME}/curve-mds.pid - -# daemon log -daemonLog=${logPath}/curve-mds-daemon.log - -# console output -consoleLog=${logPath}/curve-mds-console.log - -# 启动mds -function start_mds() { - # 检查daemon - if ! type daemon &> /dev/null - then - echo "No daemon installed" - exit 1 - fi - - # 检查curve-mds - if [ ! -f ${curveBin} ] - then - echo "No curve-mds installed" - exit 1 - fi - - # 检查配置文件 - if [ ! -f ${confPath} ] - then - echo "Not found mds.conf, Path is ${confPath}" - exit 1 - fi - - # 判断是否已经通过daemon启动了curve-mds - daemon --name curve-mds --pidfile ${pidFile} --running - if [ $? -eq 0 ] - then - echo "Already started curve-mds by daemon" - exit - fi - - # 创建logPath - mkdir -p ${logPath} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Create mds log dir failed: ${logPath}" - exit 1 - fi - - # 检查logPath是否有写权限 - if [ ! -w ${logPath} ] - then - echo "Write permission denied: ${logPath}" - exit 1 - fi - - # 检查consoleLog是否可写或者是否能够创建 - touch ${consoleLog} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create console Log: ${consoleLog}" - exit 1 - fi - - # 检查daemonLog是否可写或者是否能够创建 - touch ${daemonLog} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create daemon logfile: ${daemonLog}" - exit 1 - fi - - # 未指定mdsAddr, 从配置文件中解析出网段 - if [ -z ${mdsAddr} ] - then - subnet=`cat $confPath|grep global.subnet|awk -F"=" '{print $2}'` - port=`cat $confPath|grep global.port|awk -F"=" '{print $2}'` - prefix=`echo $subnet|awk -F/ '{print $1}'|awk -F. '{printf "%d", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'` - mod=`echo $subnet|awk -F/ '{print $2}'` - mask=$((2**32-2**(32-$mod))) - ip= - echo "subnet: $subnet" - echo "port: $port" - # 对prefix再取一次模,为了支持10.182.26.50/22这种格式 - prefix=$(($prefix&$mask)) - for i in `/sbin/ifconfig -a|grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:"` - do - # 把ip转换成整数 - ip_int=`echo $i|awk -F. '{printf "%d\n", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'` - if [ $(($ip_int&$mask)) -eq $prefix ] - then - ip=$i - break - fi - done - if [ -z "$ip" ] - then - echo "no ip matched!\n" - return 1 - fi - mdsAddr=${ip}:${port} - fi - - daemon --name curve-mds --core --inherit \ - --respawn --attempts 100 --delay 10 \ - --pidfile ${pidFile} \ - --errlog ${daemonLog} \ - --output ${consoleLog} \ - -- ${curveBin} -confPath=${confPath} -mdsAddr=${mdsAddr} -log_dir=${logPath} -graceful_quit_on_sigterm=true -stderrthreshold=3 - - sleep 1 - show_status -} - -# 停止daemon进程,且停止curve-mds -function stop_mds() { - # 判断是否已经通过daemon启动了curve-mds - daemon --name curve-mds --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start curve-mds by daemon" - exit 0 - fi - - daemon --name curve-mds --pidfile ${pidFile} --stop - if [ $? -ne 0 ] - then - echo "stop may not success!" - else - echo "curve-mds exit success!" - echo "daemon exit success!" - fi -} - -# restart -function restart_mds() { - # 判断是否已经通过daemon启动了curve-mds - daemon --name curve-mds --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start curve-mds by daemon" - exit 1 - fi - - daemon --name curve-mds --pidfile ${pidFile} --restart - if [ $? -ne 0 ] - then - echo "Restart failed" - fi -} - -# show status -function show_status() { - # 判断是否已经通过daemon启动了curve-mds - daemon --name curve-mds --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start curve-mds by daemon" - exit 1 - fi - - # 查询leader的IP - leaderAddr=`tac ${consoleLog}|grep -a -m 1 -B 1000000 "Logging before InitGoogleLogging()"|grep "leader"|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"|head -n1` - - # 如果load mds configuration之后的日志,没有leader相关日志 - # 那么leaderAddr为空, mds应该没有起来 - if [ -z ${leaderAddr} ] - then - echo "MDS may not start successfully, check log" - exit 1 - fi - - if [ ${leaderAddr} = "127.0.0.1" ] - then - echo "Current MDS is LEADER" - else - # 查询是否和自身ip相等 - for ip in `(hostname -I)` - do - if [ ${leaderAddr} = ${ip} ] - then - echo "Current MDS is LEADER" - exit - fi - done - - echo "Current MDS is FOLLOWER, LEADER is ${leaderAddr}" - fi -} - -# 使用方式 -function usage() { - echo "Usage:" - echo " ./mds-daemon.sh start -- start deamon process and watch on curve-mds process" - echo " [-c|--confPath path] mds conf path" - echo " [-l|--logPath path] mds log path" - echo " [-a|--mdsAddr ip:port] mds address" - echo " ./mds-daemon.sh stop -- stop daemon process and curve-mds" - echo " ./mds-daemon.sh restart -- restart curve-mds" - echo " ./mds-daemon.sh status -- show mds status [LEADER/STATUS]" - echo "Examples:" - echo " ./mds-daemon.sh start -c /etc/curve/mds.conf -l ${HOME}/ -a 127.0.0.1:6666" -} - -# 检查参数启动参数,最少1个 -if [ $# -lt 1 ] -then - usage - exit -fi - -case $1 in -"start") - shift # pass first argument - - # 解析参数 - while [[ $# -gt 1 ]] - do - key=$1 - - case $key in - -c|--confPath) - confPath=`realpath $2` - shift # pass key - shift # pass value - ;; - -a|--mdsAddr) - mdsAddr=$2 - shift # pass key - shift # pass value - ;; - -l|--logPath) - logPath=`realpath $2` - shift # pass key - shift # pass value - ;; - *) - usage - exit - ;; - esac - done - - start_mds - ;; -"stop") - stop_mds - ;; -"restart") - restart_mds - ;; -"status") - show_status - ;; -*) - usage - ;; -esac diff --git a/curve-snapshotcloneserver/home/nbs/snapshot-daemon.sh b/curve-snapshotcloneserver/home/nbs/snapshot-daemon.sh deleted file mode 100755 index 341428f4f4..0000000000 --- a/curve-snapshotcloneserver/home/nbs/snapshot-daemon.sh +++ /dev/null @@ -1,287 +0,0 @@ -# -# Copyright (c) 2020 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. -# - -#!/bin/bash - -# curve-snapshotcloneserver路径 -curveBin=/usr/bin/curve-snapshotcloneserver - -# 默认配置文件 -confPath=/etc/curve/snapshot_clone_server.conf - -# 日志文件路径 -logPath=/data/log/curve/snapshotclone - -# serverAddr -serverAddr= - -# pidfile -pidFile=${HOME}/curve-snapshot.pid - -# daemon log -daemonLog=${logPath}/curve-snapshot-daemon.log - -# console output -consoleLog=${logPath}/curve-snapshot-console.log - -# 启动snapshotcloneserver -function start_server() { - # 检查daemon - if ! type daemon &> /dev/null - then - echo "No daemon installed" - exit - fi - - # 检查curve-snapshotcloneserver - if [ ! -f ${curveBin} ] - then - echo "No curve-snapshotcloneserver installed, Path is ${curveBin}" - exit - fi - - # 检查配置文件 - if [ ! -f ${confPath} ] - then - echo "Not found snapshot_clone_server.conf, Path is ${confPath}" - exit - fi - - # 判断是否已经通过daemon启动了curve-snapshotcloneserver - daemon --name curve-snapshotcloneserver --pidfile ${pidFile} --running - if [ $? -eq 0 ] - then - echo "Already started curve-snapshotcloneserver by daemon" - exit - fi - - # 创建logPath - mkdir -p ${logPath} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Create log path failed: ${logPath}" - exit - fi - - # 检查logPath是否有写权限 - if [ ! -w ${logPath} ] - then - echo "Write permission denied: ${logPath}" - exit 1 - fi - - # 检查consoleLog是否可写或者能否创建,初始化glog之前的日志存放在这里 - touch ${consoleLog} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create console log: ${consoleLog}" - exit - fi - - # 检查daemonLog是否可写或者是否能够创建 - touch ${daemonLog} > /dev/null 2>&1 - if [ $? -ne 0 ] - then - echo "Can't Write or Create daemon logfile: ${daemonLog}" - exit - fi - - # 未指定serverAddr, 从配置文件中解析出网段 - if [ -z ${serverAddr} ] - then - subnet=`cat $confPath|grep server.subnet|awk -F"=" '{print $2}'` - port=`cat $confPath|grep server.port|awk -F"=" '{print $2}'` - prefix=`echo $subnet|awk -F/ '{print $1}'|awk -F. '{printf "%d", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'` - mod=`echo $subnet|awk -F/ '{print $2}'` - mask=$((2**32-2**(32-$mod))) - ip= - echo "subnet: $subnet" - echo "port: $port" - # 对prefix再取一次模,为了支持10.182.26.50/22这种格式 - prefix=$(($prefix&$mask)) - for i in `/sbin/ifconfig -a|grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:"` - do - # 把ip转换成整数 - ip_int=`echo $i|awk -F. '{printf "%d\n", ($1*(2^24))+($2*(2^16))+($3*(2^8))+$4}'` - if [ $(($ip_int&$mask)) -eq $prefix ] - then - ip=$i - break - fi - done - if [ -z "$ip" ] - then - echo "no ip matched!\n" - return 1 - fi - serverAddr=${ip}:${port} - fi - - daemon --name curve-snapshotcloneserver --core --inherit \ - --respawn --attempts 100 --delay 10 \ - --pidfile ${pidFile} \ - --errlog ${daemonLog} \ - --output ${consoleLog} \ - -- ${curveBin} -conf=${confPath} -addr=${serverAddr} -log_dir=${logPath} -stderrthreshold=3 -graceful_quit_on_sigterm=true - - sleep 1 - show_status -} - -# 停止daemon进程和curve-snapshotcloneserver -function stop_server() { - # 判断是否已经通过daemon启动了curve-snapshotcloneserver - daemon --name curve-snapshotcloneserver --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start curve-snapshotcloneserver by daemon" - exit 0 - fi - - daemon --name curve-snapshotcloneserver --pidfile ${pidFile} --stop - if [ $? -ne 0 ] - then - echo "stop may not success!" - else - echo "curve-snapshotcloneserver exit success!" - echo "daemon exit success!" - fi -} - -# restart -function restart_server() { - # 判断是否已经通过daemon启动了curve-snapshotcloneserver - daemon --name curve-snapshotcloneserver --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't started curve-snapshotcloneserver by daemon" - exit - fi - - daemon --restart --name curve-snapshotcloneserver --pidfile ${pidFile} - if [ $? -ne 0 ] - then - echo "Restart failed" - fi -} - -# show status -function show_status() { - # 判断是否已经通过daemon启动了curve-snapshotcloneserver - daemon --name curve-snapshotcloneserver --pidfile ${pidFile} --running - if [ $? -ne 0 ] - then - echo "Didn't start curve-snapshotcloneserver by daemon" - exit 1 - fi - - # 查询leader的IP - leaderAddr=`tac ${consoleLog}|grep -a -m 1 -B 1000000 "Logging before InitGoogleLogging()"|grep "leader"|grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"|head -n1` - - # 如果load configuration之后的日志,没有leader相关日志 - # 那么leaderAddr为空, snapshotcloneserver应该没有起来 - if [ -z ${leaderAddr} ] - then - echo "SnapshotClone may not start successfully, check log" - exit 1 - fi - - if [ ${leaderAddr} = "127.0.0.1" ] - then - echo "Current SnapshotClone is LEADER" - else - # 查询是否和自身ip相等 - for ip in `(hostname -I)` - do - if [ ${leaderAddr} = ${ip} ] - then - echo "Current SnapshotClone is LEADER" - exit - fi - done - - echo "Current SnapshotClone is FOLLOWER, LEADER is ${leaderAddr}" - fi -} - -# 使用方式 -function usage() { - echo "Usage:" - echo " snapshot-daemon start -- start deamon process and watch on curve-snapshotcloneserver process" - echo " [-c|--confPath path] configuration file" - echo " [-l|--logPath path] log directory" - echo " [-a|--serverAddr ip:port] listening address" - echo " snapshot-daemon stop -- stop daemon process and curve-snapshotcloneserver" - echo " snapshot-daemon restart -- restart curve-snapshotcloneserver" - echo " snapshot-daemon status -- show snapshotcloneserver status [LEADER/STATUS]" - echo "Examples:" - echo " snapshot-daemon start -c /etc/curve/snapshot_clone_server.conf -l ${HOME}/ -a 127.0.0.1:5555" -} - -# 检查参数启动参数,最少1个 -if [ $# -lt 1 ] -then - usage - exit -fi - -case $1 in -"start") - shift # pass first argument - - # 解析参数 - while [[ $# -gt 1 ]] - do - key=$1 - - case $key in - -c|--confPath) - confPath=`realpath $2` - shift # pass key - shift # pass value - ;; - -a|--serverAddr) - serverAddr=$2 - shift # pass key - shift # pass value - ;; - -l|--logPath) - logPath=`realpath $2` - shift # pass key - shift # pass value - ;; - *) - usage - exit - ;; - esac - done - - start_server - ;; -"stop") - stop_server - ;; -"restart") - restart_server - ;; -"status") - show_status - ;; -*) - usage - ;; -esac diff --git a/mk-deb.sh b/mk-deb.sh index 596ba2131c..248ddc523f 100644 --- a/mk-deb.sh +++ b/mk-deb.sh @@ -256,11 +256,6 @@ if [ $? -ne 0 ] then exit fi -cp ./curve-ansible/roles/clean/files/recycle_chunks.sh build/curve-chunkserver/home/nbs -if [ $? -ne 0 ] -then - exit -fi cp -r curve-sdk build/ if [ $? -ne 0 ] @@ -462,21 +457,11 @@ fi #then # exit #fi -mkdir -p build/curve-monitor/usr/bin -if [ $? -ne 0 ] -then - exit -fi mkdir -p build/curve-monitor/etc/curve/monitor if [ $? -ne 0 ] then exit fi -cp monitor/curve-monitor.sh build/curve-monitor/usr/bin/curve-monitor.sh -if [ $? -ne 0 ] -then - exit -fi cp -r monitor/* build/curve-monitor/etc/curve/monitor if [ $? -ne 0 ] then