Trunk Player Installation - ScanOC/trunk-player GitHub Wiki
Prerequisites
Below are the prerequisites you will need to get Trunk-Player working.
- Python3.10 Minimum. Django 5.x will not run under this.
- Redis Server
- Postgresql Database
Installing Prerequisites
- Install Prerequisites for Trunk-Player to work
sudo apt-get install python3-pip python3-dev virtualenv redis-server python3-pip postgresql libpq-dev postgresql-client postgresql-client-common git
- Delete Trunk-Player directory use to tested Trunk-Recorder. Trunk-player won't pull down if trunk-player exists with stuff in it.
sudo rm -r ~/trunk-player
Installing Trunk-Player
- Change to home directory
cd ~
- Get Trunk-Player from git repository on github.com.
git clone https://github.com/ScanOC/trunk-player.git
- Change to Trunk-Player directory.
cd trunk-player
- Make virtual environment for Python
virtualenv -p python3 env --prompt='(Trunk Player)'
- Enter virtual environment
source env/bin/activate
- Install python dependencies for Trunk-Player
pip install -r requirements.txt
- Test Trunk-Player environment is setup OK
./manage.py runworker
if manage.py give local_override error, look closer and prob see using wrong python version. Are you in the environment?
if manage.py give Django error seems it could be because pip was ran as root and shouldn't, can test by sudo ./manage.py runworker
- Exit out of virtual environment
deactivate
Configuring Trunk-Player
Editing Trunk-Player Config File
- Time to edit settings_local.py which is Trunk-Player's config file
nano ~/trunk-player/trunk_player/settings_local.py
Copy and Paste the below config to get you started
# Local devel Settings
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LOCAL_SETTINGS = True
DEBUG = True
ALLOWED_HOSTS = ['*']
# Make this unique, and don't share it with anybody.
# You can use http://www.miniwebtool.com/django-secret-key-generator/
# to create one.
SECRET_KEY = 'foxfoxfox'
# Added line to prevent CSRF verification errors with Django
SECURE_PROXY_SSL_HEADER = ()
# Name for site
SITE_TITLE = 'Local County'
SITE_EMAIL = '@twitterhandle'
DEFAULT_FROM_EMAIL='Trunk-Player WebSite <[email protected]>'
# Set this to the location of your audio files
AUDIO_URL_BASE = '/audio_files/'
# Allow TalkGroup access restrictions
ACCESS_TG_RESTRICT = False
TIME_ZONE = 'America/New_York'
# Postgres database setup
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'tplayer', # Database Name
'USER': 'trunk_player_user', # Database User Name
'PASSWORD': 'foxfoxfox', # Database User Password
'HOST': 'localhost',
'PORT': '',
}
}
See Config Documentation for more info about the above settings
Configuring Postgresql
- Change to postgres user
sudo su - postgres
- Run PostgreSQL client
psql
- Once in psql prompt, copy and paste each line below
CREATE USER trunk_player_user WITH PASSWORD 'foxfoxfox';
CREATE DATABASE tplayer;
GRANT ALL PRIVILEGES ON DATABASE tplayer TO trunk_player_user;
ALTER ROLE trunk_player_user SET client_encoding TO 'utf8';
ALTER ROLE trunk_player_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE trunk_player_user SET timezone TO 'UTC';
Change UTC to whatever timezone your linux machine is using. EG. Australia/Sydney
- Exit PostgreSQL Client
\q
- Exit postgres user account
exit
- Initiate PostgreSQL database while in ~/trunk-player directory run the below commands
source env/bin/activate
./manage.py migrate
- Create super user in Trunk-Player
./manage.py createsuperuser
- Test Trunk-Player web server
./manage.py runserver 0.0.0.0:8000
Open web browser and browse to http://(IP of Trunk-Player):80000
Install/Configuring Supervisor
- Install Supervisor
sudo apt-get install supervisor
- Make a supervisor.conf in the ~/trunk-player/trunk_player directory
nano ~/trunk-player/trunk_player/supervisor.conf
Copy and Paste below into supervisor.conf file & save file
[group:trunkplayer]
programs=trunkplayer_asgi_daphne, trunkplayer_asgi_workers, trunkplayer_add_transmission_workers
priority=999
[program:trunkplayer_asgi_daphne]
user=radio
redirect_stderr=true
stdout_logfile=/home/radio/trunk-player/logs/daphne.log
directory=/home/radio/trunk-player
command=/home/radio/trunk-player/env/bin/daphne -u daphne trunk_player.asgi:channel_layer --port 7055 --bind 127.0.0.1
[program:trunkplayer_asgi_workers]
user=radio
redirect_stderr=true
stdout_logfile=/home/radio/trunk-player/logs/runworker_%(process_num)02d.log
command=/home/radio/trunk-player/env/bin/python /home/radio/trunk-player/manage.py runworker
process_name=asgi_worker%(process_num)s
stopasgroup=true
numprocs=4
[program:trunkplayer_add_transmission_workers]
user=radio
redirect_stderr=true
stdout_logfile=/home/radio/trunk-player/logs/add_transmission_worker_%(process_num)02d.log
command=/home/radio/trunk-player/env/bin/python /home/radio/trunk-player/manage.py add_transmission_worker
process_name=add_transmission_worker%(process_num)s
stopasgroup=true
numprocs=4
- Now link it, read it, and restart sup. note the colon at end of last. its important and easy to miss
sudo ln -s /home/radio/trunk-player/trunk_player/supervisor.conf /etc/supervisor/conf.d/trunk_player.conf
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart trunkplayer:
Install/Configuring Nginx
- Install nginx
sudo apt-get install nginx
- Use the following trunk_player.nginx in trunk-player/trunk_player folder
# Sample nginx config file for trunk-player
# Enable upgrading of connection (and websocket proxying) depending on the
# presence of the upgrade field in the client request header
#map \$http_upgrade \$connection_upgrade {
#default upgrade;
#'' close;
#}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# the upstream component nginx needs to connect to
upstream trunkplayer {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:7055; # for a web port socket (we'll use this first)
}
server {
listen 80 default_server;
server_name _
charset utf-8;
client_max_body_size 75M; # adjust to taste
# audio_files
location /audio_files {
alias /home/radio/trunk-player/audio_files/;
}
location /static {
alias /home/radio/trunk-player/static; # your Django project's static files - amend as required
}
location / {
# Match PNG Icons
location ~ /.*.png$ {
root /home/radio/trunk-player/icons/;
}
# Pass request to the upstream alias
proxy_pass http://trunkplayer;
# Require http version 1.1 to allow for upgrade requests
proxy_http_version 1.1;
# We want proxy_buffering off for proxying to websockets.
proxy_buffering off;
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enable this if you use HTTPS:
# proxy_set_header X-Forwarded-Proto https;
# pass the Host: header from the client for the sake of redirects
proxy_set_header Host $http_host;
# We've set the Host header, so we don't need Nginx to muddle
# about with redirects
proxy_redirect off;
# Depending on the request value, set the Upgrade and
# connection headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto https;
}
}
- Now link up the .nginx settings and remove something then restart
sudo ln -s /home/radio/trunk-player/trunk_player/trunk_player.nginx /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
Preparing for launch
cd ..
source env/bin/activate
./manage.py collectstatic --noinput
deactivate
Launch Time
sudo systemctl restart nginx
sudo supervisorctl status
Advanced
Streaming
- Install prerequisites for streaming
sudo apt-get install sox lame
- now go to trunk-build dir and make the encode-local-sys-0.sh
cd trunk-build
nano encode-local-sys-0.sh
Paste the following into nano
#! /bin/bash
# Sample file for loading local files into trunk-player
# Dylan Reinhold 03/10/2017
# Project https://github.com/ScanOC/trunk-player
#-------------------------------------------------------
echo "Encoding: $1"
CSV_FILE="/home/radio/trunk-build/xxx.csv"
filename="$1"
basename="${filename%.*}"
filename_only=$(basename $basename)
mp3encoded="$basename.mp3"
json="$basename.json"
web_dir=$(dirname $filename | cut -d/ -f6-)"/"
system=0 # Change this for each system
dir="$(dirname $filename)"
mp3=${dir}/${filename_only}.mp3
# Hack the JSON to add play length and source
len=$(soxi -D $filename)
head -n-2 $json > $json.new
echo "\"play_length\": $len," >> $json.new
echo "\"source\": 0," >> $json.new
tail -n2 $json >> $json.new
mv $json.new $json
# this is for streamthis - lets convert to mp3 here, then delete the .wav on exit
# Start by finding the alpha tag for the talk-group:
tg="$( cut -d '-' -f 1 <<< "$filename_only" )"
ALPHA=`grep "^${tg}," ${CSV_FILE} | cut -d , -f 4`
CTIME=`date +%R`
FULLTAG="$ALPHA , Recorded at:$CTIME"
if [ -z "$ALPHA" ]
then
ALPHA="TG: ${tg}"
fi
#if [ -n "$ALPHA" ]
#then
# curtime="$(date +%R)"
# echo "Time is $curtime"
# ALPHA.=`date +%R`
# echo "CompleteAlpha is $ALPHA"
#fi
###lame --preset voice $filename $mp3encoded
#lame --nohist --gain 8 --preset voice $filename $mp3encoded
lame --nohist --gain 8 --preset voice --tt "${FULLTAG}" $filename $mp3encoded
cd /home/radio/trunk-player
. env/bin/activate
./manage.py add_transmission $basename --verbose --web_url=$web_dir --system=$system
#rm -f $filename $json
rm -f $filename
#/home/radio/liquid/streamthis $mp3
#/home/radio/liquid/streamthisfire $mp3
- Save
Control + o
- Exit
Control + x
- script will have bad permissions and I am bad at permissions so I do
sudo chmod 755 encode-local-sys-0.sh
Running Site Tweaks
By default members can only see calls going back x amount of time
To fix this set the below setting in the admin panel
Radio->Plans->Members = 0