开发者

Running SBT as Daemon

开发者 https://www.devze.com 2023-03-06 08:23 出处:网络
I have an SBT scala application that runs fine using \"sbt run\". However, this locks up the console, and I\'d rather start it as a service/daemon so that I can use the console, and also so that I can

I have an SBT scala application that runs fine using "sbt run". However, this locks up the console, and I'd rather start it as a service/daemon so that I can use the console, and also so that I can add it to init.d to ensure that my applic开发者_如何学JAVAation is started automatically on startup.

I can't seem to find a way to do this. Running "sbt run &" seems to hang the app in the background.

Does anybody know how to do this?


You could also jar up your application into a "fat" jar using either sbt-assembly or sbt-onejar.

This will make it an executable jar and easily runnable via java -jar jarname.jar.


We launch test/demo apps with SBT in init.d all the time:

#!/bin/sh
# test lift web app

case "$1" in
'start')
    cd /home/demouser/wa/HTML5DemoLift231/HTML5demo/
    sbt jetty run
    ;;
'stop')
    cd /home/demouser/wa/HTML5DemoLift231/HTML5demo/
    sbt jetty stop
    ;;
*)
    echo "Usage: $0 { start | stop }"
    ;;
esac
exit 0

This just works - we have had no problems with it. It may be different with a non-web app though.


You can use GNU Screen for keeping it in background. Anyway I can't think a good reason to do that. Whouldn't it be better to package the application and run the generated binaries in the background?


Just type sbt runProd And then press Ctrl+D The process will be running as a daemon process.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号