Wednesday, October 29, 2014

Running cherrymusic as a service in Ubuntu 14.04 with Supervisord

In the previous blog post, I showed you how to run a music streaming service on your computer:

http://iambusychangingtheworld.blogspot.com/2014/10/build-your-own-music-streaming-website.html

Today, I will guide you how to setup cherrymusic as a service using Supervisord. I love Supervisord!

I got some trouble getting cherrymusic to work with Supervisord:

* I first tried running cherrymusic with Python2: when clicking to the "browse files" link, it said that cannot browse files and throw this error in the backend:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 1: ordinal not in range(128)

* Then, I switched to Python3 and also got errors, but this time, it is a fixable issue: cherrymusic can list my albums but when I clicked to one of the album, it through this error:
...
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 7: surrogates not allowed

this is a Python3's bug: https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1227562
A workaround is to run the cherrymusic instance with LC_CTYPE="en_US.UTF-8" environment.

Here is a working Supervisord configuration for cherrymusic, /etc/supervisor/conf.d/trmusic.conf:

[program:trmusic]
directory=/path/to/cherrymusic
command=python3 cherrymusic                                                                                                           user=myusername
group=myusername
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/trmusic.log
stderr_logfile=/var/log/supervisor/trmusic_err.log
stopasgroup=true
environment = LC_CTYPE="en_US.UTF-8"


Notes: 

* you need to install cherrypy module in python3 for cherrymusic to work:

$ sudo apt-get install python3-pip
$ sudo pip3 install cherrypy

* Make sure the myusername has the proper permission on cherrymusic source folder and music folder.

* Check the configuration of cherrymusic before starting it:

$ nano ~/.config/cherrymusic/cherrymusic.conf


Finally, reload Supervisord configuration to start cherrymusic:

$ sudo supervisorctl reload