• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Deployment]: Spring Boot deployment *Systemd Service File* Error Failed to configure a DataSource

 
Greenhorn
Posts: 5
  • Number of slices to send:
    Optional 'thank-you' note:
Hi everyone I haven been struggle for 3 days with deploying Spring boot app on Linode Ubuntu Server, please help if you may, thanks in advance.

So, everything works with java -jar target/omi-0.0.1-SNAPSHOT.jar, all connections to the postgres works normal however when I try to run it with systemd/system/omi.service
I have also followed the Spring Boot Documentation, still no luck


I am facing this error. Classes and rest of stuff are posted after the log.
Error log -> Application.java -> BreafastConfiguration.java - > application.properties -> systemd/system/omi.service



Application.java

BreakfastConfiguration



application-production.properties




if you are all the way down here, thank you, and please let me know anything I should change that I can fix this problem.
 
Bartender
Posts: 3915
43
  • Number of slices to send:
    Optional 'thank-you' note:
could it be related to duplicated periods here:



 
David Ko
Greenhorn
Posts: 5
  • Number of slices to send:
    Optional 'thank-you' note:
Thanks for replying, I did removed it but still have the same issue
are there any ways that I can debug it?

I have tried ExecStart and echo some variables but it all seems ok
 
Saloon Keeper
Posts: 27851
196
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
I don't recommend using environment variables to configure Java apps. And in the case of Spring Boot, I definitely don't, because that sort of stuff would be better off in a Spring Boot config file.

Here's the setup I use to run https://gourmetj.mousetech.com:

/etc/systemd/system/systemd gourmetj.service


runme.sh

Actually, the "nohup" is left over from before I set up systemd and should probably be removed.

/home/tomcat/application.properties

There's a whole raft of places to externally configure a Spring boot app, but I took this one since I didn't need it hidden out of sight or in some sort of global context, etc.
 
Tim Holloway
Saloon Keeper
Posts: 27851
196
  • Number of slices to send:
    Optional 'thank-you' note:
Update: Yes, remove the "nohup" from the "runme.sh" and delete the "type=forking" from the service.
 
Bartender
Posts: 2421
13
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
I think this one:
spring.datasource.breakfast.driver-class-name=org.postgresql.Driver
should be replaced by
spring.datasource.driver-class-name=org.postgresql.Driver
 
Tim Holloway
Saloon Keeper
Posts: 27851
196
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
OK, It appears that this app has multiple datasources.

In that case, the syntax should be like so:


However, I would like to repeat that it's NOT a good idea to hard-code that stuff into the systemd service file. As a general rule, you don't want to put customized/changeable data into an init script or systemd file. It's better to put it in an external config file like I did. Depending on your preferences, that can be in a config directory (for example, /etc/sysconfig for Red Hat, /etc/default for Debian), a product-specific directory like /var/lib/myproduct, an "/opt" product directory such as /opt/com/mousetech/gourmetj, or, as in my case, the same directory that the product itself lives in, since it's a trivial app.

The advantages are several. First, you can make it so that you don't need full administrator privileges to change things. Secondly, it's more in tune with general Best Practices (partly because of the preceding). Thirdly, you don't have to do a "systemctl daemon-reload" every time you alter the configuration. And finally, it keeps the actual service definition down to a generic minimum of statements.

Oh, and last, but not least, you have more flexibility in your configuration syntax. For example, "application.yml":

Try doing that in a systemd service file!
 
David Ko
Greenhorn
Posts: 5
  • Number of slices to send:
    Optional 'thank-you' note:
Hi Tim and Himai,
Thanks for replying I didn’t realize there were replies, please correct if i misunderstood
And indeed i do have multiple data source

I want to point out that I have a docker compose file that create database breakfast and mesure when docker compose up, and my current situation is when I do Java -jar all the connection works fine, I have also put all my environment variables in my .bashrc (I am not sure am I wrong here)

The only problem is when I do systemctl start myservice, it just can’t recognize postgres breakfast, and when docker exec psql the database do exist.

So
1. i should not hard code any variables in Systemd service file
2. It is more flexible to use yml
3. I can place them in the config file (which I did myservice.d/myenv.conf)
Again thank you so much for answering my questions!
 
David Ko
Greenhorn
Posts: 5
  • Number of slices to send:
    Optional 'thank-you' note:
Thank you so much for your time again, I just want post some update with my files
Only systemd service has this error, ./mvnw clean package; jar -jar target/omi:0.0.1-SNAPSHOT works just fine.


Current application-production.yml

/etc/systemd/system/omi.service.d/env.conf


/etc/systemd/system/omi.service



docker postgres running normal


 
Tim Holloway
Saloon Keeper
Posts: 27851
196
  • Number of slices to send:
    Optional 'thank-you' note:
Well, the error message indicates a missing URL, but not much more. You have 3 datasources, so 3 URLs. However, only one datasource is configured in a way that Spring Boot's connection pool constructor can use it. The root of each datasource must be "spring/datasource", not "app/datasource".

Your environment file is also problematic, as it's in Windows ".ini" form, when it should be unix shell "source" form. Actually, it's not even truly valid for INI format. It seems to be a weird hybrid.

Also it's VERY bad to put the config file in /etc/systemd/system. Better locations would be "/etc/sysconfig/namex", "/var/lib/namex/" or "opt/something/namex", where the reasonable value of "namex" would be the name of the service that uses it, and "something" is your choice, although I like something like "/opt/com/coderanch" to point out that it's an app specific to my domain. In Ubuntu/Debian, instead of /etc/sysconfig/namex, I think the standard location is something like "/etc/default" and I have no idea what MacOS uses.
 
Tim Holloway
Saloon Keeper
Posts: 27851
196
  • Number of slices to send:
    Optional 'thank-you' note:
Also, Docker doesn't run under Systemd like that. A Docker container must be controlled by a "docker" command. You cannot simply put a "java jar" command in a systemd file to run a Docker container.

A Docker container for a systemd base image such as CentOS, is even more problematic. Systemd and Docker don't naturally fit together, so various contortions need to be performed to get systemd working inside a docker container.
 
David Ko
Greenhorn
Posts: 5
  • Number of slices to send:
    Optional 'thank-you' note:

Tim Holloway wrote:Also, Docker doesn't run under Systemd like that. A Docker container must be controlled by a "docker" command. You cannot simply put a "java jar" command in a systemd file to run a Docker container.

A Docker container for a systemd base image such as CentOS, is even more problematic. Systemd and Docker don't naturally fit together, so various contortions need to be performed to get systemd working inside a docker container.



Thank you Tim, no wonder by my docker doesn't work like that, I have done some google search, I have complete changed to run the spring boot from docker-compose as well, thank you for helping out!
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |