-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun_bench_init.sh
More file actions
executable file
ยท180 lines (151 loc) ยท 6.13 KB
/
run_bench_init.sh
File metadata and controls
executable file
ยท180 lines (151 loc) ยท 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
#=============================================================================
# Remote Bench Initialization Script for Frappe VPS
#=============================================================================
#
# Description:
# Copies the bench initialization script and required files to the remote
# server and executes it there. This handles the SSH connectivity and
# remote execution automatically.
#
# Prerequisites:
# - Dependencies setup completed
# - SSH key authentication configured
# - config.yml with site configuration
#
# What this script does:
# 1. Validates local configuration
# 2. Tests SSH connectivity to server
# 3. Copies bench init script and utilities to remote server
# 4. Executes bench initialization remotely
# 5. Cleans up temporary files
#
# Author: Generated for Frappe VPS Setup
# Dependencies: config.yml, utils.sh, bench_init.sh
#=============================================================================
set -euo pipefail
# Get script directory and source utilities
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/utils.sh"
# Configuration file path
CONFIG_FILE="$SCRIPT_DIR/config.yml"
# SSH options for hardened server
SSH_OPTS="-o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=~/.ssh/known_hosts"
# Function to load configuration
load_remote_config() {
load_config "$CONFIG_FILE"
# Set configuration variables
SERVER_IP="${CONFIG_server_ip_address:-}"
FRAPPE_USERNAME="${CONFIG_frappe_username:-resilient}"
BENCH_NAME="${CONFIG_frappe_bench_name:-resilient-bench}"
SITE_NAME="${CONFIG_frappe_site_name:-}"
SSH_PORT="8520" # Fixed port after hardening
# Validate required configuration
if [[ -z "$SERVER_IP" ]]; then
print_error "Server IP not found in configuration"
exit 1
fi
if [[ -z "$SITE_NAME" ]]; then
print_error "Site name is required but not found in configuration"
print_error "Please set 'frappe.site_name' in config.yml"
exit 1
fi
if ! validate_ip_address "$SERVER_IP"; then
print_error "Invalid IP address format: $SERVER_IP"
exit 1
fi
}
# Function to test SSH connection
test_remote_connection() {
print_info "Testing SSH connection to $FRAPPE_USERNAME@$SERVER_IP:$SSH_PORT"
if ! ssh $SSH_OPTS -p $SSH_PORT "$FRAPPE_USERNAME@$SERVER_IP" "echo 'Connection successful'" 2>/dev/null; then
print_error "Failed to connect to $FRAPPE_USERNAME@$SERVER_IP:$SSH_PORT"
print_error ""
print_error "Please ensure:"
print_error " 1. Dependencies setup has been completed"
print_error " 2. SSH is running on port $SSH_PORT"
print_error " 3. User '$FRAPPE_USERNAME' exists with SSH key access"
print_error " 4. Server is accessible at $SERVER_IP"
exit 1
fi
print_info "SSH connection successful!"
}
# Function to copy required files to remote server
copy_files_to_remote() {
print_info "Copying bench initialization files to remote server..."
# Create temporary directory on remote server
ssh $SSH_OPTS -p $SSH_PORT "$FRAPPE_USERNAME@$SERVER_IP" "mkdir -p ~/frappe_bench_init_temp"
# Copy required files
scp $SSH_OPTS -P $SSH_PORT \
"$SCRIPT_DIR/config.yml" \
"$SCRIPT_DIR/utils.sh" \
"$SCRIPT_DIR/bench_init.sh" \
"$FRAPPE_USERNAME@$SERVER_IP:~/frappe_bench_init_temp/"
# Make scripts executable
ssh $SSH_OPTS -p $SSH_PORT "$FRAPPE_USERNAME@$SERVER_IP" \
"chmod +x ~/frappe_bench_init_temp/bench_init.sh ~/frappe_bench_init_temp/utils.sh"
print_info "Files copied successfully"
}
# Function to run bench initialization on remote server
run_bench_init_remotely() {
print_info "Starting Frappe bench initialization on remote server..."
print_info "Site: $SITE_NAME"
print_info "This may take 10-15 minutes depending on your server..."
# Execute the bench init script remotely from home directory
# Copy the script to temp directory but run it from home directory
if ssh $SSH_OPTS -p $SSH_PORT "$FRAPPE_USERNAME@$SERVER_IP" \
"cd ~ && ~/frappe_bench_init_temp/bench_init.sh"; then
print_info "Bench initialization completed successfully!"
else
print_error "Bench initialization failed!"
print_error "Check the output above for details"
exit 1
fi
}
# Function to clean up temporary files
cleanup_remote_files() {
print_info "Cleaning up temporary files..."
ssh $SSH_OPTS -p $SSH_PORT "$FRAPPE_USERNAME@$SERVER_IP" \
"rm -rf ~/frappe_bench_init_temp" 2>/dev/null || true
print_info "Cleanup completed"
}
# Main execution
main() {
print_info "Starting Remote Frappe Bench Initialization"
print_info "==========================================="
# Load and validate configuration
load_remote_config
print_info "Target server: $SERVER_IP:$SSH_PORT"
print_info "Target user: $FRAPPE_USERNAME"
print_info "Site name: $SITE_NAME"
# Test connection
test_remote_connection
# Copy files and execute remotely
copy_files_to_remote
run_bench_init_remotely
cleanup_remote_files
print_info ""
print_success "๐ Remote Frappe bench initialization completed successfully!"
print_info ""
print_info "โ
Summary:"
print_info " โ Connected to server ($FRAPPE_USERNAME@$SERVER_IP:$SSH_PORT)"
print_info " โ Copied bench initialization files"
print_info " โ Initialized Frappe bench with site: $SITE_NAME"
print_info " โ Saved admin credentials to ~/frappe_admin_credentials.txt"
print_info " โ Cleaned up temporary files"
print_info ""
print_info "๐ Connect to your server and start development:"
print_info " ssh -p $SSH_PORT $FRAPPE_USERNAME@$SERVER_IP"
print_info " cd $BENCH_NAME"
print_info " bench start"
print_info ""
print_info "๐ Access your site:"
print_info " http://$SITE_NAME:8000"
print_info ""
print_info "๐ Check credentials:"
print_info " cat ~/frappe_admin_credentials.txt"
print_info ""
print_success "๐ Frappe is ready for development!"
}
# Run main function
main "$@"