Spring Boot应用在使用SSH时启动失败

huangapple go评论133阅读模式
英文:

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

以下是几个链接,以帮助未来的开发者入门:

英文:

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

huangapple
  • 本文由 发表于 2020年3月16日 02:54:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/60696507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定