Programmatically restart Spring Boot application

前端 未结 3 682
挽巷
挽巷 2020-12-20 13:11

I\'m using Spring Boot and I\'ve got a use case where user can upload a file which should cause a restart of application (since user\'s upload is used during creation of mul

3条回答
  •  眼角桃花
    2020-12-20 13:26

    I have a special case in which my Spring Boot application, which runs on Linux, is required to run as root.

    Since I run the application as systemd service, I can restart it like this:

    Runtime.getRuntime().exec(new String[] { "/bin/systemctl", "restart", "foo" });
    

    If your application is (hopefully) not required to run as root, a setuid wrapper-script could be used, or better, use sudo.

    Check this answer on how to do that:

    https://superuser.com/questions/440363/can-i-make-a-script-always-execute-as-root

提交回复
热议问题