I need to start Apache Karaf inside a docker image with baseimage-docker, Karaf is a Java server normally started using karaf shell script that doesn't act as a daemon so halts shell when launched.
I created /etc/service/karaf/run script to execute it:
#!/bin/sh
exec 2>&1
exec /opt/karaf/bin/karaf server
The problem is that that shell script execute a java command so I think I can say that "it forks":
root@de46c21a2a5f:/opt/karaf# ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:31 ? 00:00:00 /usr/bin/python3 -u /sbin/my_init
root 7 1 0 10:31 ? 00:00:00 /usr/bin/runsvdir -P /etc/service
root 8 7 0 10:31 ? 00:00:00 runsv karaf
root 9 7 0 10:31 ? 00:00:00 runsv sshd
root 10 7 0 10:31 ? 00:00:00 runsv syslog-ng
root 11 7 0 10:31 ? 00:00:00 runsv syslog-forwarder
root 12 7 0 10:31 ? 00:00:00 runsv cron
root 13 12 0 10:31 ? 00:00:00 /usr/sbin/cron -f
root 14 10 0 10:31 ? 00:00:00 syslog-ng -F -p /var/run/syslog-ng.pid --no-caps
root 15 11 0 10:31 ? 00:00:00 tail -F -n 0 /var/log/syslog
root 16 8 0 10:31 ? 00:00:00 /bin/bash /opt/karaf/bin/karaf server
root 68 16 35 10:31 ? 00:00:10 /usr/lib/jvm/jdk1.7.0_80/bin/java -server -Xms128M -Xmx512M -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Dcom.su
root 100 0 0 10:31 ? 00:00:00 /bin/bash
root 153 100 0 10:31 ? 00:00:00 ps -eaf
root@de46c21a2a5f:/opt/karaf#
Just take a look at PID 16 and 68, PID 16 is my runit shell script, PID 68 is Java process launched by it.
I know that this shouldn't be done
Note that the shell script must run the daemon without letting it daemonize/fork it.
In fact I can't stop PID 68 using
The only alternative that I know is calling java executable directly in runit script, but I don't want to do that because I should skip many checks done by karaf shell script and java commands wouldn't be recalculated by the script in some cases.
Executing my server at docker container startup is not a problem, but I'd like to use runit service restart features in case of java process crash to keep my server continously alive.
Does anyone have a solution to make this works? Consider that many Java server or applications acts in the same way, so it's a general problem.
Thanks for your support
Andrea