| #!/bin/bash |
|
|
| echo "===== Application Startup at $(date) =====" |
| whoami |
| cat /etc/passwd |
|
|
| echo "===== System Information =====" |
| uname -a |
| echo "CPU: $(lscpu | grep 'Model name' | cut -f 2 -d ":")" |
| echo "Memory: $(free -h | awk '/^Mem:/ {print $2}')" |
| echo "Disk: $(df -h / | awk 'NR==2 {print $2}')" |
| echo "===============================" |
|
|
| |
| if [ ! -f /etc/dropbear/dropbear_rsa_host_key ]; then |
| echo "Generating RSA host key..." |
| dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key |
| fi |
|
|
| |
| echo "Starting Dropbear..." |
| dropbear -R -p 2202 -w -E -F & |
|
|
| |
| for i in {1..10}; do |
| if netstat -tuln | grep :2202 > /dev/null; then |
| echo "Dropbear started successfully on port 2202" |
| break |
| fi |
| if [ $i -eq 10 ]; then |
| echo "Failed to start Dropbear after 10 attempts" |
| exit 1 |
| fi |
| echo "Waiting for Dropbear to start... (attempt $i)" |
| sleep 1 |
| done |
|
|
| echo "Dropbear version: $(dropbear -V 2>&1)" |
|
|
| |
| echo "Testing SSH connection..." |
| if ssh -p 2202 -o StrictHostKeyChecking=no user@localhost 'echo "SSH connection successful"'; then |
| echo "SSH connection test passed" |
| else |
| echo "SSH connection test failed" |
| exit 1 |
| fi |
|
|
| |
| echo "Dropbear process:" |
| ps aux | grep dropbear | grep -v grep |
|
|
| |
| echo "Listening ports:" |
| netstat -tuln | grep LISTEN |
|
|
| |
| echo "Starting Node.js application..." |
| npm start |
|
|
| |
| if ! pgrep -f "node app.js" > /dev/null; then |
| echo "Failed to start Node.js application" |
| exit 1 |
| fi |
|
|
| echo "Node.js application started successfully" |