On Mon, 11.01.16 20:19, Christopher (ctubbsii-fedora@xxxxxxxxxx) wrote: > Hi, > > I'm a co-maintainer for ZooKeeper, and I'd like to help get this right, if > possible. More importantly, I'm interested in setting a precedent for Java > system services in systemd. So, forgive my ignorance, but what exactly is > the generally recommended way of launching Java-based applications as > system services in systemd? Is there a good model to follow? A Java service > that gets this right? I am not a Java programmer, so I don't really know how Java works that well. But if you can double fork() in Java you should be fine and can implement correct Type=forking (i.e. SysV) semantics, but I have the suspicion that Java doesn't really permit the concept of fork()... Alternatively, you could implement Type=notify semantics, i.e implement in Java the equivalent of sd_notify(). It's trivial actually, you just send a single AF_UNIX/SOCK_DGRAM datagram with a newline separated string to the socket specified in $NOTIFY_SOCKET. See the NOTES section in sd_notify(3) about this. That said, I have the suspicion that Java might not allow you to use AF_UNIX/SOCK_DGRAM sockets, either? If that's the case, then you could add a trivial JNI wrapper around the C routine that is sd_notify(), and get Type=notify semantics that way... I think there's also this: https://commons.apache.org/proper/commons-daemon/ Not sure how current this is, but it might get you Type=forking semantics too. But I have no idea what this really does, it could be that it's not actually really implementing proper UNIX semantics... > Also, as I understand it, Java processes don't really fork in any way > that's useful here. The JVM has it's own internal threading model. So, > what's the best way for them to play nice with systemd? Should they all be > simple? Or should they all be launched by a shell script which implements > the double-forking paradigm? If the latter, wouldn't that add a lot of > complication that systemd is designed to eliminate with the simplicity of > writing units? You cannot really implement the double-forking concept with shell scripts only. Also, and most importantly you really need some kind of notification concept to indicate completion of initialization. That can either be sd_notify() for Type=notify mode, or something internal+exit() in the parent for Type=forking mode, but it must be something. Lennart -- Lennart Poettering, Red Hat -- devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxxx http://lists.fedoraproject.org/admin/lists/devel@xxxxxxxxxxxxxxxxxxxxxxx