[systemd-devel] Java program that prompts password using systemd service
Dinesh Prasanth Moluguwan Krishnamoorthy
dmoluguw at redhat.com
Wed Nov 28 00:07:41 UTC 2018
Hi,
I'm trying to write a Java program that queries user for password. The
difficulty I'm facing is, this java program is started using `systemd`
service.
I'm aware that `systemd` services are meant to run non-interactively.
I'm trying to change it based on my program's need.
I was reading about `ProcessBuilder` in Java to invoke `systemd-ask-
password` command.
public static void main(String arg[]) {
try {
ProcessBuilder pb = new
ProcessBuilder();// padd user nuxwdog:internalDB mkdtest1 @u"});
pb.command("/bin/bash", "-c", "systemd-ask-
password internaldb: --no-output");
pb.inheritIO();
Process p = pb.start();
int exitCode = p.waitFor();
assert exitCode == 0;
System.out.println(exitCode);
}
}
I get the following `journalctl` logs when I start using systemd. I'm
not prompted for password.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopping
pki-tomcatd-nuxwdog at pki-tomcat.service...
Nov 27 18:25:35 localhost.localdomain java[7034]: 143
Nov 27 18:25:35 localhost.localdomain systemd[1]:
pki-tomcatd-nuxwdog at pki-tomcat.service: Main process exited,
code=exited, status=143/n/a
Nov 27 18:25:35 localhost.localdomain systemd[1]:
pki-tomcatd-nuxwdog at pki-tomcat.service: Failed with result 'exit-code'.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopped
pki-tomcatd-nuxwdog at pki-tomcat.service.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Started
pki-tomcatd-nuxwdog at pki-tomcat.service.
Is there a way to query a password interactively from a Java program
started using a systemd service?
Thanks,
Dinesh
More information about the systemd-devel
mailing list