Read Console input on spring boot with tomcat

后端 未结 4 1283
轮回少年
轮回少年 2021-02-20 01:12

Is it possible to read console input just before the embedded tomcat on the spring boot starts? The supposedly application flow is, request username and password from the user,

4条回答
  •  长发绾君心
    2021-02-20 01:39

    If you want to full log with console input like logger + System.out.println() outputs, then you have to use

    nohup java -jar yourJarFile.jar admin password >> fullLogOutput.log &
    

    Another issue:

    the problem is when I close the console(SSH on linux) the process stops.

    So you want to run your jar file as background process. You can't stop it with your console closing. Just add & symbol after full command, it will not stop. You can use the following command.

    nohup java -jar yourJarFile.jar &
    

    For taking full log with console output

    nohup java -jar yourJarFile.jar >> fullLogOutput.log &
    

    The & symbol is used to run the program in the background.

    The nohup utility makes the command passed as an argument run in the background even after you log out.

    Stopping/Killing the back-end process:

    For stopping the background process, use ps -aux to get the id and then kill (id number)

    ps -aux | grep yourJarFile.jar
    

    You will get the id number. To kill that

    sudo kill -9 
    

    Resource Link: https://stackoverflow.com/a/12108646/2293534

提交回复
热议问题