Skip to content

Commit

Permalink
curve-nbd: change auto mount service to systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanHai authored and ilixiaocui committed Nov 19, 2021
1 parent 2b2850a commit 7dd82d6
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 29 deletions.
32 changes: 32 additions & 0 deletions curve-ansible/clean_nbd.yml
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 2 additions & 0 deletions curve-ansible/client.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions curve-ansible/roles/clean/tasks/include/clean_nbd.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions curve-ansible/roles/install_package/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mk-tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`
Expand Down
6 changes: 4 additions & 2 deletions nbd/nbd-package/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nbd/nbd-package/DEBIAN/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions nbd/nbd-package/etc/systemd/system/map_curve_disk.service
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions nbd/nbd-package/usr/bin/map_curve_disk.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7dd82d6

Please sign in to comment.