Skip to content

Commit

Permalink
corrected cehck__writable to only check touch and not rm
Browse files Browse the repository at this point in the history
uniondrive rm removes the files but throws error
  • Loading branch information
ehsan6sha committed Apr 22, 2024
1 parent 8b9d00d commit 8b6d20d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ check_files_and_folders() {
}

check_writable() {
if touch "/uniondrive/.tmp3_write_check" && rm "/uniondrive/.tmp3_write_check"; then
return 0 # Success
# Try to create a temporary file
touch "/uniondrive/.tmp3_write_check"

# Check if the file exists after attempting to create it
if [ -f "/uniondrive/.tmp3_write_check" ]; then
# Attempt to remove the file regardless of the outcome
rm -f "/uniondrive/.tmp3_write_check"
# Return success even if 'rm' fails
return 0
else
return 1 # Failure
# Return failure if the file could not be created
return 1
fi
}

Expand Down
15 changes: 12 additions & 3 deletions docker/fxsupport/linux/kubo/kubo-container-init.d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ check_files_and_folders() {
}

check_writable() {
if touch "/uniondrive/.tmp2_write_check" && rm "/uniondrive/.tmp2_write_check"; then
return 0 # Success
# Try to create a temporary file
touch "/uniondrive/.tmp2_write_check"

# Check if the file was created successfully
if [ -f "/uniondrive/.tmp2_write_check" ]; then
# Attempt to remove the file, ignoring whether removal is successful
rm -f "/uniondrive/.tmp2_write_check" 2>/dev/null

# Return success since the file was created (indicating the drive is writable)
return 0
else
return 1 # Failure
# Return failure if the file could not be created
return 1
fi
}

Expand Down
14 changes: 11 additions & 3 deletions docker/fxsupport/linux/union-drive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ DISK_INDEX=0

create_disk_link() {
if mountpoint -q "$1"; then
existing_link=$(hget "$1")
if [ -n "$existing_link" ]; then
echo "Link already exists for $1: $MOUNT_LINKS/$existing_link"
return 0
fi

DISK_INDEX=$((DISK_INDEX+1))
LINK_NAME="disk-$DISK_INDEX"
ln -s "$1" "$MOUNT_LINKS/$LINK_NAME"
ln -s "$1" "$MOUNT_LINKS/$LINK_NAME"
hput "$1" "$LINK_NAME"
echo "Created link $LINK_NAME for $1"
else
echo "Skipping $1, not a mount point."
fi
Expand Down Expand Up @@ -146,14 +153,15 @@ done

while true; do
systemd-notify WATCHDOG=1
cleanup_mounts
grep "$MOUNT_USB_PATH" /proc/mounts |
while IFS= read -r line; do
if [ ! -s "$line" ]; then
mount_path=$(echo "$line" | cut -d ' ' -f 2)
if [ -n "$mount_path" ] && mountpoint -q "$mount_path"; then
if [ -d "$mount_path" ] && mountpoint -q "$mount_path"; then
create_disk_link "$mount_path"
fi
fi
done
sleep 20
sleep 10
done
29 changes: 21 additions & 8 deletions docker/go-fula/go-fula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,45 @@ wait_for_ipfs() {


check_writable() {
is_writable=0 # Assume both directories are writable initially

# Check if /internal exists and is writable
if [ -d "/internal" ]; then
if ! touch /internal/.tmp_write || ! rm /internal/.tmp_write; then
touch /internal/.tmp_write 2>/dev/null
if [ -f /internal/.tmp_write ]; then
rm /internal/.tmp_write 2>/dev/null
else
log "/internal is not writable."
return 1
is_writable=1
fi
else
log "/internal does not exist."
return 1
is_writable=1
fi

# Check if /uniondrive exists and is writable
if [ -d "/uniondrive" ]; then
if ! touch /uniondrive/.tmp_write || ! rm /uniondrive/.tmp_write; then
touch /uniondrive/.tmp_write 2>/dev/null
if [ -f /uniondrive/.tmp_write ]; then
rm /uniondrive/.tmp_write 2>/dev/null
else
log "/uniondrive is not writable."
return 1
is_writable=1
fi
else
log "/uniondrive does not exist."
return 1
is_writable=1
fi

log "Both /internal and /uniondrive exist and are writable."
return 0
if [ $is_writable -eq 0 ]; then
log "Both /internal and /uniondrive exist and are writable."
return 0
else
return 1
fi
}


check_interfaces() {
# Check for required commands
if ! command -v ip > /dev/null 2>&1; then
Expand Down
31 changes: 23 additions & 8 deletions docker/sugarfunge-node/run_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,47 @@ export IPFS_PORT=5001
export NODEAPI_PORT=4000

check_writable() {
# Initialize success flag
success=0

# Check if /internal exists and is writable
if [ -d "/internal" ]; then
if ! touch /internal/.tmp_write || ! rm /internal/.tmp_write; then
touch "/internal/.tmp_write" 2>/dev/null
if [ -f "/internal/.tmp_write" ]; then
rm "/internal/.tmp_write" 2>/dev/null
else
echo "/internal is not writable."
return 1
success=1
fi
else
echo "/internal does not exist."
return 1
success=1
fi

# Check if /uniondrive exists and is writable
if [ -d "/uniondrive" ]; then
if ! touch /uniondrive/.tmp_write || ! rm /uniondrive/.tmp_write; then
touch "/uniondrive/.tmp_write" 2>/dev/null
if [ -f "/uniondrive/.tmp_write" ]; then
rm "/uniondrive/.tmp_write" 2>/dev/null
else
echo "/uniondrive is not writable."
return 1
success=1
fi
else
echo "/uniondrive does not exist."
return 1
success=1
fi

echo "Both /internal and /uniondrive exist and are writable."
return 0
# Final status check
if [ $success -eq 0 ]; then
echo "Both /internal and /uniondrive exist and are writable."
return 0
else
return 1
fi
}


check_chain_synced() {
# POST request to the health endpoint
response=$(curl -s -X POST http://127.0.0.1:4000/health)
Expand Down

0 comments on commit 8b6d20d

Please sign in to comment.