-1

I have created a fat-jar for my apache camel 3 route. I put that on my raspberry pi (bullseye) in /opt/myhome and could start it successfully with java 17 (also works with sudo):

/usr/bin/java -jar /opt/myhome/myhome-1.0-SNAPSHOT-jar-with-dependencies.jar

Then I have added /lib/systemd/system/myhome.service as:

[Unit]
Description=My home automation with apache camel 3.
After=network.target

[Service]
ExecStart=/usr/bin/java -jar /opt/myhome/myhome-1.0-SNAPSHOT-jar-with-dependencies.jar > /var/log/myhome.log 2>&1

[Install]
WantedBy=network.target

Then I did:

sudo systemctl daemon-reload
sudo systemctl enable myhome.service
sudo systemctl start myhome.service

After starting and waiting for some seconds I executed

systemctl status myhome.service

Which displays me

● myhome.service - My home automation with apache camel 3.
 Loaded: loaded (/lib/systemd/system/myhome.service; enabled; vendor preset: enabled)
 Active: inactive (dead) since Fri 2022-10-07 18:28:52 CEST; 1h 18min ago
Process: 18159 ExecStart=/usr/bin/java -jar /opt/myhome/myhome-1.0-SNAPSHOT-jar-with-dependencies.jar > /var/>
Main PID: 18159 (code=exited, status=0/SUCCESS)
    CPU: 10.174s

systemd[1]: Started My home automation with apache camel 3..
java[18159]: WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
java[18159]: Apache Camel Runner takes the following options
java[18159]:   -h or -help = Displays the help screen
java[18159]:   -r or -routers <routerBuilderClasses> = Sets the router builder classes which will be loaded while starting the camel context
java[18159]:   -d or -duration <duration> = Sets the time duration (seconds) that the application will run for before terminating.
java[18159]:   -dm or -durationMaxMessages <durationMaxMessages> = Sets the duration of maximum number of messages that the application will process before terminating.
java[18159]:   -di or -durationIdle <durationIdle> = Sets the idle time duration (seconds) duration that the application can be idle before terminating.
java[18159]:   -t or -trace = Enables tracing
java[18159]:   -ts or -traceStandby = Enables tracing standby
java[18159]:   -e or -exitcode <exitcode> = Sets the exit code if duration was hit
java[18159]:   -pl or -propertiesLocation <propertiesLocation> = Sets location(s) to load properties, such as from classpath or file system.
systemd[1]: myhome.service: Succeeded.
systemd[1]: myhome.service: Consumed 10.174s CPU time.

So this means the process was started, but then not the same as when starting the jar manually happens, but a help message seems to appear.

So the question is, why did the jar behaves differently as when started manually?

I also tested to change the code in myhome.service to:

/usr/bin/java -jar /opt/myhome/myhome-1.0-SNAPSHOT-jar-with-dependencies.jar -e 10 -d 60 -r de.powerstat.camel.homeautomation.HomeautomationRouteBuilder > /var/log/myhome.log 2>&1

Which results in the same as above. So no different exit code because of a timeout, or a not found route class.

What point did I miss here?

Update 1:

Completed the systemctl status output. Looks like this comes from org.apache.camel.main.MainCommandLineSupport

So the question is still why this shows up when starting in systemd context and not when starting within the bash?

Within my jar file the META-INF/MANIFEST.MF looks like:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: PowerStat
Build-Jdk: 17.0.2
Main-Class: de.powerstat.camel.homeautomation.MainApp

while the MainApp class is defined as follows:

public class HomeautomationRouteBuilder extends RouteBuilder
PowerStat
  • 3,757
  • 8
  • 32
  • 57
  • I’m voting to close this question because questions about systemd are for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com. – Rob Oct 08 '22 at 10:10
  • For me this is a programing question, because Camel3 behaves differently in the normal and the systemd environment. – PowerStat Oct 09 '22 at 18:28
  • 1
    The issue isn't happening when programming, compiling, etc and the linux people do know how to run a java program without being java programmers because they know systemd. Regarding your fix, `>` redirection is a shell feature and I guess there is no shell interpreting happening in `ExecStart`. https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file has a solution with running it with `sh -c` which adds a shell interpreter into the mix (That question is also wrong here :D) – zapl Oct 13 '22 at 20:21
  • Infrastructue as code (Iac) would make it possible ;-) – PowerStat Oct 14 '22 at 12:26

1 Answers1

1

After some research I found out that "> /var/log/myhome.log 2>&1" will be passed as three parameters to args. Because these parameters are not recognized results in the shown help message.

PowerStat
  • 3,757
  • 8
  • 32
  • 57