exec / start.sh
aigems's picture
ok
21dc2d1
raw
history blame
1.79 kB
#!/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 "==============================="
# 检查并生成 SSH 主机密钥(如果不存在)
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
# 启动 Dropbear,使用 2202 端口,允许密码认证,后台运行
echo "Starting Dropbear..."
dropbear -R -p 2202 -w -E -F &
# 检查 Dropbear 是否成功启动
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)"
# 测试 SSH 连接
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
# 显示 Dropbear 进程信息
echo "Dropbear process:"
ps aux | grep dropbear | grep -v grep
# 显示监听端口
echo "Listening ports:"
netstat -tuln | grep LISTEN
# 启动 Node.js 应用
echo "Starting Node.js application..."
npm start
# 检查 Node.js 应用是否成功启动
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"