Search code examples
ubunturaspberry-piosgisystemdapache-felix

How to start a service with systemd in Raspbian Buster Lite which starts an felix (OSGi) program and holds the bundles active?


I have the following problem: I have an Raspberry Pi with the Raspbian Buster Lite operating system. I want to automatically start an program with the start of the Raspberry Pi.

I'm trying this with systemd by creating a service in the folder /etc/systemd/system. The program I want to start is an Apache Felix file to start OSGi-Bundles. If I start this file on the Raspberry Pi everything works normally. By starting the program with systemd, the service is active, but the bundles of the Felix file are immediately stopped after every bundle started. I want the bundles to stay active. I tried many things, here an example:

[Unit]
Description=Service to run felix

[Service]
User=module
Group=module
Type=simple
WorkingDirectory=/home/module/apache-felix-6.0.2/apache-felix-6.0.2
ExecStart=/home/module/apache-felix-6.0.2/apache-felix-6.0.2/startFelix.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

With this, like described above, the serivce is active, but the bundles are all stopped after they started successfully. I also tried it with forking and RemainAfterExit = yes. Still the same problem. After research I found that with a service type oneshot and RemainAfterExit = yes the service stays active after starting. But this didn't solve the problem, because the bundles of the Felix file are stopped although the service is still active. I also tried to set KillMode to none and the KillSignal to an signal whos default action is to ignore the signal, but it also doesn't work. I set the KillSignal to SIGCHLD.

Here the startFelix.sh script:

#!/bin/bash

java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8182 -Dlogback.configurationFile=conf/logback.xml -jar ./bin/felix.jar

How is it possible to hold the bundles active? Has anybody an idea?


Solution

  • I still have no idea why it doesn't work with systemd, but I tried it with supervisor and everything works fine without stopping the bundles.

    The configuration file looks like:

    [program:felix]
    command = /home/module/apache-felix-6.0.2/apache-felix-6.0.2/startFelix.sh
    directory = /home/module/apache-felix-6.0.2/apache-felix-6.0.2
    user = module
    autostart = true
    stdout_logfile = /home/module/supervisor/felix.log
    stdout_logfile_maxbytes=500KB
    stdout_logfile_backups=1
    stderr_logfile = /home/module/supervisor/felix_err.log
    stderr_logfile_maxbytes=500KB
    stderr_logfile_backups=1
    environment = HOME="/home/module/apache-felix-6.0.2/apache-felix-6.0.2", USER="module"