英文:
Spring Boot app fails to start up using SSH
问题
我有一个在staging和prod服务器上正常运行的Spring应用程序。现在是时候自动化部署了。
我在我的staging服务器上有一个restart.sh
脚本。如果我作为用户通过SSH登录服务器并运行它,一切正常。
运行命令:nohup ./restart.sh
# restart.sh
kill $(ps -aux | grep plenti-app | grep java | awk '{print $2}')
java -jar -Dspring.profiles.active=staging plenti-app
然而,当我尝试通过SSH运行命令时,它失败并显示数据库密码验证失败。
ssh user@$STAGING_IP "./restart.sh"
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "gszbybjk"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:520) ~[postgresql-42.2.9.jar!/:42.2.9]
我最初怀疑这可能与环境变量有关,因为我是通过环境变量存储数据库凭据的,但是对ssh user@ip echo $DB_PASSWORD
的调用返回了预期的值。
英文:
I have a spring app that is happily running on a staging and a prod server. It's time to automate deployments.
I have a restart.sh
script on my staging server. if I ssh
into the server and run it as a user everything works as expected.
command to run: nohup ./restart.sh
# restart.sh
kill $(ps -aux | grep plenti-app | grep java | awk '{print $2}')
java -jar -Dspring.profiles.active=staging plenti-app
However, when I attempt to run the command through ssh, it fails saying that password authentication for my database fails.
ssh user@$STAGING_IP "./restart.sh"
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "gszbybjk"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:520) ~[postgresql-42.2.9.jar!/:42.2.9]
I first suspected that this might have to do with environment variables since that's how I'm storing the database credentials, but ssh calls to ssh user@ip echo $DB_PASSWORD
result in the expected value.
答案1
得分: 0
结果证明,我走错了方向。有一个完整的子系统专门用于启动服务应用,称为 systemd
。
以下是几个链接,以帮助未来的开发者入门:
- https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-systemd-service
- https://stackoverflow.com/questions/31242291/add-additional-parameters-to-spring-boot-app
- https://stackoverflow.com/questions/21503883/spring-boot-application-as-a-service
英文:
Turns out, I was going about this the wrong way. There's a whole subsystem dedicated to launching service applications called systemd
Here are several links to help any future travelers get started
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论