SOLVED: For whatever reason, a system-level environment variable is not accessible for a service running using *systemd*. Takes me by surprise, I thought system-level environment variables would be visible to all users.
But, one can define the environment variable in the .service file, using either *Environment=* or *EnvironmentFile=* . This article explains it pretty well "Using environment variables in systemd units <https://www.flatcar.org/docs/latest/setup/systemd/environment-variables/>" After adding the line Environment=PATH_TO_SHIFTSTARTSDB=/var/lib/shiftstarts/ShiftStartsDB the invocation within *application.properties* is expanding, and the application is running and connecting to the persistent H2 database. On Friday, January 24, 2025 at 7:43:16 PM UTC-8 philfrei1 wrote: > Thanks for your help, and for the link to the "external-config.html" > section. I am having a great deal of difficulty discerning what is relevant > to my situation from this document! > > I hope to use the same jar for my home/test Ubuntu OS and my remote server > Ubuntu OS. I thought that by providing that absolute address via an > environment variable I'd be able to locate the .jar and database in > appropriate but different locations for the two system. If there is > another, more appropriate way to do this...? > > "environment of the service process is not the same as environment of your > user" > The environment variable "PATH_TO_SHIFTSTARTSDB" is set in > */env/environment*. This makes the variable visible for the entire > system, yes? If so, the environment of the user should not matter, correct? > > FWIW here is the *shiftstarts.service* file. I probably should have > posted it from the start of this thread. > > [Unit] > Description=Service ShiftStartsUPS > After=syslog.target > > [Service] > ExecStart=/usr/lib/jvm/java-17-openjdk-amd64/bin/java -jar > /var/lib/shiftstarts-ups/shiftstarts-0.0.1.jar > SuccessExitStatus=143 > User=phil > > [Install] > WantedBy=multi-user.target > > ### End of file ### > > And what is most puzzling to me, if I simply manually type in the java > -jar command that is in the ExecStart, I don't get the error. The program > runs as designed. In fact, one can see the point where the environment > variable is expanded: > > ... com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Starting... > ... com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added > connection conn0: url=jdbc:h2:file:/var/lib/shiftstarts-ups/StartTimeDB > user=UPSER > > In the journalctl for the failed run, we have the following: > > ... com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Starting... > ... o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 90011, SQLState: > 90011 > ... o.h.engine.jdbc.spi.SqlExceptionHelper : A file path that is > implicitly relative ... etc. > > > I will next see if I can locate documentation about "HikariPool". > On Friday, January 24, 2025 at 12:27:51 AM UTC-8 Evgenij Ryazanov wrote: > >> Hello! >> >> JDBC URLs passed to database drivers usually can't contain any variables, >> so there is nothing to do on H2 side. >> >> But Spring Boot provides multiple ways for such configurations: >> https://docs.spring.io/spring-boot/reference/features/external-config.html >> For example, you can have a configuration file on the system like many >> other system services have. >> System environment variables are also supported, but environment of the >> service process is not the same as environment of your user, so maybe your >> variable is not defined for your service or something else is wrong. >> > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/h2-database/3a9fef4d-1277-44b9-95d8-562b4118a284n%40googlegroups.com.
