简体   繁体   中英

Spring not seen environment variables from systemd service

I'm trying to run spring boot app with systemd service of ubuntu. In my service file, I have ExecStart variable

ExecStart=/bla/run.sh

And variables:

Environment="DB_HOSTNAME=ip"
Environment="DB_PORT=5432"
...

(I have tried both variants: with and without braces)

My sh file looks like:

#!/bin/sh

echo jdbc:postgresql://${DB_HOSTNAME}:${DB_PORT}/${DB_NAME}
sudo /usr/bin/java -jar bla.jar

Inside sh variables are available as well, but spring application does not deal with them. The same with the active profile variable.

I thought that the problem is about the scope of variables and I tried to pass them to another sh from the main one. But in another script they are available, so the problem only with spring app.

Update Trick with export does not help

Maybe it will helpful for somebody. The main problem was using sudo for starting java app. After removing sudo variables become available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM