1
1
#! /bin/bash
2
2
3
+ # Enable error checking and debugging
4
+ set -e # Exit on any error
5
+ set -x # Print each command before executing
6
+
3
7
# Log startup for debugging
4
8
echo " Starting initialization script..."
5
9
6
- # Create parent directories first with error checking
7
- echo " Creating directory structure..."
8
- sudo mkdir -p /mnt/stateful_partition || {
9
- echo " Failed to create stateful_partition directory"
10
- exit 1
11
- }
10
+ # Check if directory exists first and show current permissions
11
+ echo " Checking current state..."
12
+ ls -la /mnt || true
13
+ ls -la /mnt/stateful_partition || true
12
14
13
- # Create qi-agents directory
14
- sudo mkdir -p /mnt/stateful_partition/qi-agents || {
15
- echo " Failed to create qi-agents directory"
15
+ # Try creating base directory first
16
+ echo " Creating base directory..."
17
+ if ! sudo mkdir -p /mnt/stateful_partition; then
18
+ echo " Failed to create /mnt/stateful_partition"
19
+ # Try to identify the issue
20
+ df -h
21
+ mount | grep /mnt
22
+ ls -la /mnt
16
23
exit 1
17
- }
24
+ fi
25
+
26
+ # Try alternative locations if stateful_partition isn't working
27
+ if [ ! -d " /mnt/stateful_partition" ]; then
28
+ echo " Using alternative directory /var/lib/qi-agents"
29
+ sudo mkdir -p /var/lib/qi-agents || {
30
+ echo " Failed to create alternative directory"
31
+ exit 1
32
+ }
33
+ AGENT_DATA_DIR=" /var/lib/qi-agents"
34
+ else
35
+ AGENT_DATA_DIR=" /mnt/stateful_partition/qi-agents"
36
+ # Create qi-agents directory
37
+ sudo mkdir -p " $AGENT_DATA_DIR " || {
38
+ echo " Failed to create qi-agents directory"
39
+ exit 1
40
+ }
41
+ fi
18
42
19
43
# Create data directory
20
- sudo mkdir -p /mnt/stateful_partition/qi-agents/data || {
44
+ echo " Creating data directory in $AGENT_DATA_DIR ..."
45
+ sudo mkdir -p " $AGENT_DATA_DIR /data" || {
21
46
echo " Failed to create data directory"
22
47
exit 1
23
48
}
24
49
25
- # Set permissions
50
+ # Set permissions with verbose output
26
51
echo " Setting directory permissions..."
27
- sudo chmod -R 777 /mnt/stateful_partition/qi-agents || {
52
+ sudo chmod -Rv 777 " $AGENT_DATA_DIR " || {
28
53
echo " Failed to set permissions"
29
54
exit 1
30
55
}
31
56
32
- # Verify directory structure
57
+ # Verify directory structure and permissions
33
58
echo " Verifying directory structure..."
34
- ls -la /mnt/stateful_partition/qi-agents/
59
+ ls -la " $AGENT_DATA_DIR "
60
+ ls -la " $AGENT_DATA_DIR /data"
35
61
36
62
# Pull latest image with verification
37
63
echo " Pulling latest image..."
@@ -52,7 +78,7 @@ echo "Starting container..."
52
78
docker run -d \
53
79
--name ${FULL_NAME} \
54
80
--restart=always \
55
- -v /mnt/stateful_partition/qi-agents/ data:/app/agent/data \
81
+ -v " $AGENT_DATA_DIR / data" :/app/agent/data \
56
82
-e AGENTS_BUCKET_NAME=" ${AGENTS_BUCKET_NAME} " \
57
83
-e CHARACTER_FILE=" ${CHARACTER_FILE} " \
58
84
-e SMALL_GOOGLE_MODEL=" ${SMALL_GOOGLE_MODEL} " \
@@ -70,5 +96,11 @@ if ! docker ps | grep ${FULL_NAME}; then
70
96
exit 1
71
97
fi
72
98
73
- # Log success
99
+ # Final verification
100
+ echo " Verifying final state..."
101
+ df -h
102
+ mount
103
+ docker ps
104
+ ls -la " $AGENT_DATA_DIR "
105
+
74
106
echo " Startup script completed successfully"
0 commit comments