-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
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 | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
update-rc.d map_curve_disk.sh remove | ||
rm -f /etc/init.d/map_curve_disk.sh | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# /etc/curvetab | ||
# use for auto map and mount curve disk when boot | ||
# | ||
# this file record the correspondence of curve nbd images/ devices | ||
# add record when 'curve-nbd map' and 'curve-nbd unmap' | ||
# | ||
# format: device image mount | ||
# /dev/nbd0 cbd:pool//curvefile_test_ /curve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/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 | ||
confPath=/etc/curve/curvetab | ||
|
||
# check sudo | ||
if [[ $(id -u) -ne 0 ]] | ||
then | ||
echo "Please run with sudo" | ||
exit 1 | ||
fi | ||
|
||
# usage | ||
function usage() { | ||
echo "Usage: ./map_curve_disk.sh start" | ||
echo " -c/--confPath: set the confPath (default /etc/curve/curvetab)" | ||
echo " file format is:dealflag \t device \t image \t mountpoint(option)" | ||
echo " example: + /dev/nbd0 cbd:pool//curvefile_test_ /test" | ||
echo " -h/--help: get the script usage" | ||
echo "Examples:" | ||
echo " ./map_curve_disk.sh start //use the default configuration" | ||
echo " ./map_curve_disk.sh start --confPath yourConfPath //use the new confPath" | ||
} | ||
|
||
# remove extra records | ||
function dealcurvetab() { | ||
if [ ! -f ${confPath} ] | ||
then | ||
echo "ERROR: not found configuration file, confPath is ${confPath}!" | ||
exit | ||
fi | ||
|
||
declare -A recordmap | ||
while read line | ||
do | ||
flag=$(echo $line | awk '{print $1}') | ||
device=$(echo $line | awk '{print $2}') | ||
if [ "$flag" = "+" ] | ||
then | ||
recordmap["$device"]=$line | ||
elif [ "$flag" = "-" ] | ||
then | ||
unset recordmap[$device] | ||
fi | ||
done < ${confPath} | ||
for key in ${!recordmap[@]}; do | ||
echo ${recordmap[$key]} >> ${confPath}.bak | ||
done | ||
} | ||
|
||
# map the curve disk based on curvetab | ||
function map() { | ||
if [ ! -f ${confPath}.bak ] | ||
then | ||
echo "ERROR: not found configuration file, confPath is ${confPath}.bak!" | ||
exit | ||
fi | ||
|
||
cat ${confPath}.bak | grep -v '#' | while read line | ||
do | ||
device=$(echo $line | awk '{print $2}') | ||
image=$(echo $line | awk '{print $3}') | ||
mount=$(echo $line | awk '{print $4}') | ||
curve-nbd map $image --device $device | ||
if [ "$mount" != "" ] | ||
then | ||
mount $device $mount | ||
fi | ||
done | ||
mv ${confPath}.bak ${confPath} | ||
} | ||
|
||
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 | ||
;; | ||
*) | ||
usage | ||
exit | ||
;; | ||
esac | ||
done | ||
dealcurvetab | ||
map | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters