How to install and configure CherryMusic on a Debian

Installation

CherryMusic depends on Python. To install Python 3, issue:

apt-get install python3

now install dependencies:

apt-get install ffmpeg imagemagick python3-unidecode lame flack vorbis-tools

Config

Create user dedicated account:

adduser cherrymusic

The easiest way to get the latest CherryMusic code and to update CherryMusic regularly is to use Git. Install Git with:

apt-get install git

Now, switch to the newly created user:

su cherrymusic

and get CherryMusic:

git clone --branch devel git://github.com/devsnd/cherrymusic.git /home/cherrymusic/cherrymusic-devel
cd /home/cherrymusic/cherrymusic-devel
python3 ./cherrymusic --help

cherry1

cherry2

Now, do the initial startup to generate the configuration and data files in your home directory:

python3 ./cherrymusic

This creates the configuration file “~/.config/cherrymusic/cherrymusic.conf”

now we need to edit the config file:

nano~/.config/cherrymusic/cherrymusic.conf

under “basedir” enter the path to your music collection – to make it easier to add further libraries I set the “basedir” to a folder /home/cherrymusic/music_dir and created symlinks in that directory pointing to the location of my music

mkdir /home/cherrymusic/music_dir
ln -s Path_to_your_music /home/cherrymusic/music_dir

now we need to update the cherrymusic database:

python3./cherrymusic--update

and then start the server to test it:

python3./cherrymusic

 

Finalization

By default cherrymusic will run on http – for security we will set it to run on https:

I already have certificate created and openssl installed so I go ahead and change the CherryMusic config:

cd /home/cherrymusic/cherrymusic-devel
 nano ~/.config/cherrymusic/cherrymusic.conf

and change the following lines accordingly:

[...]
 ssl_enabled = True
 [...]
 ssl_certificate = /etc/ssl/certs/server.crt
 [...]
 ssl_private_key = /etc/ssl/private/server.key
 [...]

Now, when you connect to CherryMusic, you should automatically be redirected to the SSL port and therefore have a secure connection.

sysvinit startup script

One final thing is to set it up as a service – instructions are provided on Lord-Simon’s github:
https://github.com/Lord-Simon/Scripts/tree/master/cherrymusic

wget --no-check-certificate https://github.com/Lord-Simon/Scripts/raw/master/cherrymusic/cherrymusic -O /etc/init.d/cherrymusic

then make the file executable:

chmod +x /etc/init.d/cherrymusic

open it for editing:

nano /etc/init.d/cherrymusic

and:
1. Add the path of your cherrymusic folder to DIR (/home/cherrymusic/cherrymusic-devel)
2. Add the python executable path to the PYTHON (/usr/bin/python3)
3. Set the USER and GROUP under which the service will run

Test the the init script by running:

service cherrymusic start

 

Once all is working OK do this:

update-rc.d /etc/init.d/cherrymusic defaults

 

Systemd startup script

I recently moved my cherrymusic service to brand new debian 8 box running systemd and so here is the systemd service script:

[Unit]
Description=CherryMusic Service
After=network.target

[Service]
User=cherrymusic
ExecStart=/usr/bin/python3 /home/cherrymusic/folder/cherrymusic #use your path to cm

[Install]
WantedBy=multi-user.target

saved that file to /etc/systemd/system as a cherrymusic.service
then to start it up just run:

systemctl start cherrymusic

to ensure it starts automatically enable the service:

systemctl enable cherrymusic

cherry3

Raspberry Pi – Debian – Network tools

ifstat – InterFace STATistics Monitoring

ifstat is a tool to report network interfaces bandwith just like vmstat/iostat do for other system counters. It can monitor local interfaces by polling the kernel counters, or remote hosts interfaces using SNMP.

To install run:

apt-get install ifstat

then just issue:

ifstat

example output:

eth0
 KB/s in KB/s out
 4.22 237.91
 4.19 246.90
 4.17 248.41

to be continued….

Optimizing Raspberry Pi performance

CPU

The best way to overclock Raspberry Pi it is with the raspi-config tool

raspi-config

I go for the Modest option:

 

Nginx

Modify nginx.con (/etc/nginx/nginx.conf)

We only have one CPU thread…

worker_processes  1;

In the http { section add the following:

# Optimize memory
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
sendfile        on;
tcp_nopush     on;
server_names_hash_bucket_size 128;
keepalive_timeout  65;
# Enable website compression - it takes a lot of CPU
# If you are running low on CPU disable the Zip part.
gzip  on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

Also it is usefull to add:

#Hide Nginx version number
 server_tokens off;

 

 MySQL

Download and run this script: MySQL Tuner Perl script

perl mysqltuner.pl

then go to /etc/mysql/ and edit my.cnf accordingly.

 

Monitoring Raspberry Pi performance

CPU and Running processes

I use the classic: top. Installed as standard in our distributions, It will display the processes running and sort them according to certain criteria.

Here for example that the command returns on my server :

By default, the command will sort the programs by their CPU usage. To change the sorting press: ‘ f’ to select fields to display, then you move with the arrows. The SPACEBAR to display a field then ‘ s’ to use the field as default sort.

 Memory usage

To get some extra RAM reduce the graphics memory to 1MB using raspi-config tool:

Another great tool:

Disk Usage

 Webmin

There is always webmin that will give you some additional info:

Setting up NoIP on Raspberry Pi

Install No-IP client:

Create a directory for the client software

mkdir /home/noip
cd /home/noip

Download and extract the client software

wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar vzxf noip-duc-linux.tar.gz

Now install the software:

cd noip-2.1.9-1
 make
 make install

Next provide your NoIP username, password and refresh interval.
To start the program run:

/usr/local/bin/noip2

Setup automatic startup

nano /etc/init.d/noip

and paste this:

#! /bin/sh
 # /etc/init.d/noip
 ### BEGIN INIT INFO
 # Provides: noip
 # Required-Start: $remote_fs $syslog
 # Required-Stop: $remote_fs $syslog
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: Simple script to start a program at boot
 # Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
 ### END INIT INFO
 # If you want a command to always run, put it here
 # Carry out specific functions when asked to by the system
 case "$1" in
 start)
 echo "Starting noip"
 # run application you want to start
 /usr/local/bin/noip2
 ;;
 stop)
 echo "Stopping noip"
 # kill application you want to stop
 killall noip2
 ;;
 *)
 echo "Usage: /etc/init.d/noip {start|stop}"
 exit 1
 ;;
 esac
 exit 0

Make script executable:

chmod 755 /etc/init.d/noip

Test starting the program:

/etc/init.d/noip start

Test stopping the program:

/etc/init.d/Noip stop

Register script to be run at start-up:

update-rc.d noip defaults