Skip to content

Instantly share code, notes, and snippets.

@zentrope
Last active October 21, 2015 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentrope/1d6d359d347a1c03e99f to your computer and use it in GitHub Desktop.
Save zentrope/1d6d359d347a1c03e99f to your computer and use it in GitHub Desktop.
nginx, mont and shell for running and monitoring a java process on a unix (FreeBSD) system
#!/bin/sh
app="cipher"
version="0.9.2"
java="/usr/local/bin/java"
daemon="/usr/sbin/daemon"
app_home="/home/vagrant/apps/${app}"
jar="${app}-${version}-standalone.jar"
pid="${app_home}/${app}.pid"
logfile="${app_home}/${app}.stdout.log"
command="${java} -jar ${app_home}/${jar}"
case $1 in
start)
cd ${app_home}
${daemon} -p ${pid} ${command} 2>&1 >> ${logfile}
echo "done."
;;
stop)
echo "Shutting down." >> ${logfile}
/bin/kill `cat ${pid}`
;;
*)
echo "usage: ${app}.sh {start|stop}"
;;
esac
exit 0
set daemon 60 with start delay 60
set pidfile /var/run/monit.pid
set idfile /var/.monit.id
set statefile /var/.monit.state
set logfile syslog
set httpd port 2812 and
use address localhost
allow localhost
allow admin:monit
check process cipher with pidfile /home/vagrant/apps/cipher/cipher.pid
start program = "/home/vagrant/apps/cipher/cipher.sh start" as uid "vagrant" and gid "vagrant"
stop program = "/home/vagrant/apps/cipher/cipher.sh stop" as uid "vagrant" and gid "vagrant"
if failed port 2112 protocol HTTP
request /ping
with timeout 10 seconds
then restart
http {
server {
listen 80;
server_name websocket.local;
location / {
proxy_pass http://127.0.0.1:2112;
}
location /ws {
proxy_pass http://127.0.0.1:2112/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 30m; # for long running idle sockets
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment