I use the following script run (on CentOS) for my Play application, it seems to be working fine, it puts it in the background and in its own process group and session, so it is immune to hangs, etc. The advice on the play stage
and target/start
comes from Guillaume Bort and is the "right way to do it."
#!/bin/bash # # chkconfig: 2345 98 1 # description: MyApp application # case "$1" in start) su - apps <<'EOF' cd /opt/myapp || exit 1 PATH=/opt/play-2.1.1:$PATH echo "Starting MyApp..." play stage setsid target/start < /dev/null > /dev/null 2>&1 & EOF ;; stop) su - apps <<'EOF' cd /opt/myapp || exit 1 PATH=/opt/play-2.1.1:$PATH echo "Stopping MyApp..." play stop EOF ;; esac
You can check it for availability:
ps -e -o user,pid,ppid,pgrp,sid,command | grep -i play
You will see something like:
apps 2949 1 2949 2949 java -cp target/staged/* play.core.server.NettyServer target/..
The value init
(pid 1
) is its parent and is isolated in its own process group ( 2949
).
source share