This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "create/remove tmp_dir in monogdb-node code"
- Loading branch information
Showing
7 changed files
with
163 additions
and
168 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
138 changes: 0 additions & 138 deletions
138
jobs/mongodb_node_ng/templates/create_mongodb_tmp_dir.erb
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,160 @@ | ||
#!/bin/bash | ||
|
||
LOG_DIR=/var/vcap/sys/log/mongodb_node | ||
|
||
mkdir -p $LOG_DIR | ||
log_echo() { | ||
echo "`date` $1" >> $LOG_DIR/tmp_dir_ctl.log | ||
} | ||
|
||
create_tmp_file() { | ||
size=$1 | ||
file_path=$2 | ||
/usr/bin/truncate -s ${size}M ${file_path} | ||
if [ ! $? -eq 0 ]; then | ||
log_echo "ERROR: fail to create the loop file for mongodb tmp directory" | ||
# delete the incomplete file | ||
rm -rf $file_path | ||
exit 1 | ||
else | ||
chmod 0700 $file_path | ||
fi | ||
} | ||
|
||
mongodb_tmp_in=/var/vcap/store | ||
mongodb_tmp_loop_file="$mongodb_tmp_in/mongodb_tmp_loop" | ||
mongodb_tmp_dir="/var/vcap/store/tmp_dir" | ||
# unit of size should be MB, default size is 10GB | ||
mongodb_tmp_size=<%= properties.mongodb_node.max_tmp || 10240 %> | ||
# greedy_level, recreate files and directories if possible, may delete the file and direcotry with the same names or, just report | ||
greedy_level=<%= properties.mongodb_node.tmp_greedy_level || 1 %> | ||
|
||
|
||
|
||
case $1 in | ||
create) | ||
will_create_file=0 | ||
will_setup_loop=0 | ||
will_create_dir=0 | ||
# check whether the mongodb_tmp_loop has been created, if not, try to create it | ||
|
||
if [ ! -f "$mongodb_tmp_loop_file" ]; then | ||
create_tmp_file $mongodb_tmp_size $mongodb_tmp_loop_file | ||
fi | ||
|
||
size=`stat -c %s $mongodb_tmp_loop_file` | ||
expect_size=`expr $mongodb_tmp_size \* 1024 \* 1024` | ||
|
||
if [ ! "$size" = "$expect_size" ]; then | ||
if [ $greedy_level -eq 0 ]; then | ||
# graceful, just notify | ||
log_echo "ERROR: there is a tmp loop file which has different size" | ||
exit 1 | ||
else | ||
# not graceful, will delete the old file and recreate a new one if possible | ||
will_create_file=1 | ||
fi | ||
fi | ||
|
||
ret=`losetup -a | grep "$mongodb_tmp_loop_file"` | ||
if [ ! -z "$ret" ]; then | ||
loop_dev=`echo "$ret" | cut -d: -f1` | ||
if [ -d "$mongodb_tmp_dir" ]; then | ||
check_mount=`mount -l | grep "$loop_dev" | grep "$mongodb_tmp_dir"` | ||
if [ ! -z "$check_mount" ]; then | ||
if [ $will_create_file -eq 0 ]; then | ||
# usually, starting mongodb will come here | ||
chown vcap $mongodb_tmp_dir | ||
exit 0 | ||
fi | ||
else | ||
if [ $greedy_level -eq 0]; then | ||
log_echo "ERROR: $mongodb_tmp_dir exists but not mounted to $loop_dev" | ||
exit 1 | ||
else | ||
# must recreate the directory for mounting | ||
will_create_dir=1 | ||
fi | ||
fi | ||
else | ||
# must create a new directory for mounting | ||
will_create_dir=1 | ||
fi | ||
else | ||
loop_dev=`losetup -f` | ||
if [ $? -ne 0 ]; then | ||
log_echo "ERROR: fail to get one free loop device" | ||
exit 1 | ||
fi | ||
will_setup_loop=1 | ||
if [ -d "$mongodb_tmp_dir" ]; then | ||
if [ $greedy_level -eq 0]; then | ||
log_echo "ERROR: $mongodb_tmp_dir exists but not mounted to the new loop device: $loop_dev" | ||
exit 1 | ||
else | ||
# must recreate the directory for mounting | ||
will_create_dir=1 | ||
fi | ||
else | ||
# must create a new directory for mounting | ||
will_create_dir=1 | ||
fi | ||
fi | ||
|
||
if [ $will_create_file -eq 1 ]; then | ||
# delete the old file | ||
umount -d $mongodb_tmp_dir | ||
rm -rf $mongodb_tmp_dir | ||
losetup -d $loop_dev | ||
rm -rf $mongodb_tmp_loop_file | ||
|
||
create_tmp_file $mongodb_tmp_size $mongodb_tmp_loop_file | ||
|
||
will_setup_loop=1 | ||
will_create_dir=1 | ||
fi | ||
|
||
if [ $will_setup_loop -eq 1 ]; then | ||
losetup $loop_dev $mongodb_tmp_loop_file | ||
if [ $? -ne 0 ]; then | ||
log_echo "ERROR: fail to bind the loop device with the loop file" | ||
exit 1 | ||
fi | ||
mke2fs -t ext4 $loop_dev | ||
if [ $? -ne 0 ]; then | ||
log_echo "ERROR: fail to make ext4 filesystem" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ $will_create_dir -eq 1 ]; then | ||
umount -d $mongodb_tmp_dir | ||
mkdir -p $mongodb_tmp_dir | ||
mount -t ext4 $loop_dev $mongodb_tmp_dir | ||
if [ $? -ne 0 ]; then | ||
log_echo "ERROR: fail to mount $loop_dev to $mongodb_tmp_dir" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
chown $SUDO_USER $mongodb_tmp_dir | ||
;; | ||
|
||
remove) | ||
ret=$(mountpoint "$mongodb_tmp_dir") | ||
if [ $? -eq "0" ]; then | ||
ret=$(umount -d $mongodb_tmp_dir 2>&1) | ||
if [ $? -eq "0" ]; then | ||
log_echo "successfully umount $mongodb_tmp_dir" | ||
else | ||
log_echo "failed to umount $mongodb_tmp_dir: $ret" | ||
fi | ||
fi | ||
|
||
;; | ||
|
||
*) | ||
echo "Usage: $0 {create|remove}" | ||
|
||
;; | ||
esac |
Submodule services
updated
from a021c8 to 240d05