Category Archives: Play Framework

My Play Framework logrotate configuration

Here is another script I need to keep handy for the future. My logrotate script for Play Framework applications. The important thing here is the parameter “copytruncate”. I tried many times without it and the result was always the same: after the logrotate was done no more logging was made by the application. “copytruncate” solved this

/opt/myapp/logs/*.log {
  missingok
  notifempty
  size 50M
  copytruncate
  create 0644 root root
  rotate 9999
}

How to run logrotate manually:

logrotate --force /etc/logrotate.d/myapp

Tested on Ubuntu 14.04 and Play Framework 2.3

My Play Framework Upstart script

Recently I had to create a upstart script for a Play application and this was the result of that. I put it here so I don’t have to start from scratch next time 🙂

########################################################################################################
#
#                                       Upstart Script
#
# Upstart script for a play application. Put this into a file like /etc/init/myapp.conf
#
# This could be the foundation for pushing play apps to the server using something like git-deploy
# By calling service play stop in the restart command and play-start in the restart command.
#
# Usage:
#   sudo start myapp
#   sudo stop myapp
#   sudo restart myapp
#   sudo status myapp
#
#########################################################################################################
 
description "Upstart script for MyApp"
author "Niklas Ottosson"
version "1.0"
 
# Set environment variables
env HOME=/my/app/dir/
env LANG=en_US.UTF-8
 
# Start and stop runlevels
start on runlevel [2345]
stop on runlevel [06]
 
# Respawn parameters with limit: dies 3 times within 60 seconds
respawn
respawn limit 3 60
 
# Change directory to current version of Tankmin
chdir /my/app/dir/
 
# Delete any stray PIDs
pre-start script
  rm -f ${HOME}/RUNNING_PID
end script
 
# Upstart logging (/var/log/upstart/myapp.log)
console none
 
# TEST ENVIRONMENT (arguments here are what I'm using for this particular app - you should use what works best for your app)
exec bin/myapp -J-Xms256M -J-Xmx768m -J-server -Dhttp.port=80 -Dconfig.file=conf/application.conf -Dlogger.file=conf/application-logger_PROD.xml

Tested in a production environment on Ubuntu 14.04 and Play Framework 2.3

Charset problem in Play framework after upgrading OSX

This is such a strange problem that I just have to write it down for future reference.
Involved systems:
* One Ubuntu 14.04.2 LTS on AWS (Amazon Web Services)
* One MacBook Pro 2010 with 10.7.5 with iTerm 2.1.1
* One MacBook Pro 2015 with 10.10.3 with iTerm 2.1.1
* One Play framework 2.3 application

Problem description:
After starting the Play application with the MacBook that has the 10.10.3 version all files that were written to disk had all non-ascii characters shown as ??. When starting the Play application with the old computer (10.7.5) these characters where displayed correctly.

After quite a lot of trial-and-error I found that the command ‘locale’ on the remote AWS server complained about:
“locale: Cannot set LC_CTYPE to default locale: No such file or directory”
“locale: Cannot set LC_ALL to default locale: No such file or directory”
when using the newer computer but not with the old

Solution:
The ‘locale’ command error lead me to the following solution in iTerm:
Untick the Terminal option “Set locale variables automaticly” in Preference
QQ20140113-3

This option is AFAIK default on in iTerm

After this was done the ‘locale’ error was gone and all files had the correct charset