2

I tried to find a solution for the following use case (on Linux):

  1. Start the program, show some information to the stdout, input some information such as username/password.
  2. The program validate the username/password, then goes to background and run as a daemon.

I did not find a way to do this in Java. There are several sulotions to daemonize java program (such as jsvc, or this: http://barelyenough.org/blog/2005/03/java-daemon/ ). But seems they all do not work for this situation, because the program just goes to background from the beginning, there is no chance to input information before it goes to background.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rainfield
  • 1,172
  • 2
  • 14
  • 29
  • Would it work starting it as a service? – vitro Jun 05 '14 at 19:54
  • why need information from the stdin and not, say, a configuration file in /etc ? note that inputting the password in stdin isn't that much more secure that a single user readable file - if you root the machine you can just get the pass out of the process memory – Lorenzo Boccaccia Jun 05 '14 at 23:13
  • @LorenzoBoccaccia I think that's much secure than putting it in a file for most of the people. – Rainfield Jun 06 '14 at 01:05

1 Answers1

0

I don't believe that there's a way to do this purely in java. You could make it work by writing an init script which accepted the command line parameters before spawning the java process in the background. You could use -D command line arguments to pass the user input to the java process.

Daniel Scott
  • 7,418
  • 5
  • 39
  • 58