Difference between revisions of "Subsonic"

From ArchWiki
Jump to: navigation, search
(updated info about subsonic/madsonic being not foss anymore.)
 
(41 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Audio/Video]]
+
[[Category:Multimedia]]
'''Subsonic''' is a music server that lets you store your music on one machine and play it from other machines, cell phones, via a web interface, or various other applications. It can be installed using the {{AUR|subsonic}} package on [[AUR]].
+
'''Subsonic''' is a music server that lets you store your music on one machine and play it from other machines, cell phones, via a web interface, or various other applications. It can be installed using the {{AUR|subsonic}} package on [[AUR]]. As of version 6, the software is not open source anymore.
  
==Additional config==
+
==Configuration==
===Run subsonic daemon NOT as root===
+
  
Stop subsonic daemon is running
+
After performing any configuration, remember to [[restart]] {{ic|subsonic.service}}.
  
# rc.d stop subsonic
+
===Install transcoders===
  
Add a system user "subsonic" without home folder and add it to "audio" group if you want to use the "jukebox" feature
+
By default, Subsonic uses FFmpeg to transcode videos and songs to an appropriate format and bitrate on-the-fly. After installation, you can change these defaults so that, for example, Subsonic will transcode FLAC files using FLAC and LAME instead of FFmpeg. You should therefore [[Install]] the {{Pkg|ffmpeg}}, and you may also want to install {{Pkg|flac}} and {{Pkg|lame}}.
  
# useradd --system --groups audio subsonic
+
For security reasons, Subsonic will not search the system for any transcoders. Instead, the user must create symlinks to the transcoders in the {{ic|/var/lib/subsonic/transcode}} folder. Create the symlinks like so:
  
Change folder owners as follow. Path may changes; these are the default ones:
+
$ cd /var/lib/subsonic/transcode
 +
# for transcoder in ffmpeg flac lame; do ln -s "$(which $transcoder)"; done
  
# chown -R subsonic:subsonic /tmp/subsonic
+
=== HTTPS Setup ===
# chown -R subsonic:subsonic /var/subsonic
+
# chown -R root:root /var/subsonic/transcode
+
# chown -R root:root /var/subsonic/jetty/*/webapp
+
  
Change this line in {{ic|/var/subsonic/subsonic.sh}}
+
==== With Subsonic ====
  
${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m \
+
To enable HTTPS browsing and streaming, edit {{ic|/var/lib/subsonic/subsonic.sh}} and change this line:
  
with this one
+
SUBSONIC_HTTPS_PORT=0
  
sudo -u subsonic ${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m \
+
To this:
  
Restart subsonic daemon
+
SUBSONIC_HTTPS_PORT=8443
  
# rc.d start subsonic
+
{{Note|port 8443 seems hard-coded somewhere. When attempting to change it to port 8080 it will automatically redirect the browser to port 8443 after manually accepting the invalid HTTPS certificate. You will still be able to re-navigate to port 8080 after the warning page and have it work on that port.}}
  
===Install LAME and FFmpeg for Transcoding ===
+
==== With Nginx ====
Subsonic requires LAME to be installed to transcode songs in mp3 format to lower bit rates. Also requieres FFmpeg to transcode from other formats (as ogg, flac, wav or wma) to mp3 format or to stream video files.
+
If not already installed, [[pacman|Install]] the {{Pkg|lame}} and {{Pkg|ffmpeg}} package, available in the [[Official Repositories|official repositories]].
+
  
Put a symlink to LAME in the transcode directory for subsonic.
+
If you already have multiple web services running, it might be easier to use a single SSL configuration everywhere. The following Nginx configuration runs Subsonic under https://example.com/subsonic :
  
# ln -s /usr/bin/lame /var/subsonic/transcode/lame
+
{{bc|server {
 +
    listen              443 default ssl;
 +
    server_name        example.com;
 +
    ssl_certificate    cert.pem
 +
    ssl_certificate_key key.pem
  
Put a symlink to FFmpeg in the transcode directory for subsonic.
+
    location /subsonic {
# ln -s /usr/bin/ffmpeg /var/subsonic/transcode/ffmpeg
+
      proxy_set_header X-Real-IP        $remote_addr;
 +
      proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
 +
      proxy_set_header X-Forwarded-Proto https;
 +
      proxy_set_header Host              $http_host;
 +
      proxy_max_temp_file_size          0;
 +
      proxy_pass                        http://127.0.0.1:4040;
 +
      proxy_redirect                    http:// https://;
 +
    }
 +
} }}
  
Restart subsonic daemon
+
To run Subsonic under a different path, you have to set the following options in {{ic|/var/lib/subsonic/subsonic.sh}} :
# rc.d start subsonic
+
  
=== Systemd Setup ===
+
{{bc|1=SUBSONIC_CONTEXT_PATH=/subsonic
 +
SUBSONIC_HOST=127.0.0.1
 +
SUBSONIC_PORT=4040
 +
SUBSONIC_HTTPS_PORT=0}}
  
Create a service file in /usr/lib/systemd/system called subsonicd.service with this content:
+
==Troubleshooting==
+
{{bc|
+
[Unit]
+
Description=Subsonic
+
After=network.target
+
  
[Service]
+
===FLAC playback===
Type=forking
+
ExecStart=/var/subsonic/subsonic.sh
+
ExecStop=/bin/kill -15 $MAINPID
+
  
[Install]
+
The FFmpeg transcoder doesn't handle FLAC files well, and clients will often fail to play the resultant streams. (at least, on [[User:Ichimonji10|my]] machine) Using FLAC and LAME instead of FFmpeg solves this issue. This workaround requires that the FLAC and LAME transcoders have been installed, as explained in [[#Install transcoders]].
WantedBy=multi-user.target
+
}}
+
  
Then, run:
+
Start Subsonic and go to {{ic|settings > transcoding}}. Ensure that the default FFmpeg transcoder does not get used on files with a "flac" extension, then add a new entry. You'll end up with something like this:
  
# sudo systemctl --system daemon-reload
+
{| class="wikitable"
 +
! Name !! Convert from !! Convert to !! Step 1 !! Step 2
 +
|-
 +
| mp3 default || ... NOT flac ... || mp3 || ffmpeg ... ||  
 +
|-
 +
| mp3 flac || flac || mp3 || flac --silent --decode --stdout %s || lame --silent -h -b %b -
 +
|}
  
And finally enable it:
+
===UTF-8 file names not added to the database===
  
# sudo systemctl enable subsonicd.service
+
{{Out of date|The default init system under Arch is now Systemd, not SysV.}}
  
==Troubleshooting==
 
===UTF-8 file names not added to the database===
 
 
You must have at least one UTF-8 [[locale]] installed.
 
You must have at least one UTF-8 [[locale]] installed.
  
 
If you start subsonic using {{ic|/etc/rc.d/subsonic}}, and your /etc/[[rc.conf]] has {{ic|<nowiki>DAEMON_LOCALE="no"</nowiki>}}, then the subsonic daemon will be started with the C locale, and Java will skip any folders with "international characters" (e.g. ßðþøæå etc.). Either set {{ic|DAEMON_LOCALE}} to {{ic|"yes"}} (but this will affect '''all''' rc.daemons), or add a line to the beginning of {{ic|/var/subsonic/subsonic.sh}} which sets {{ic|LANG}} to an installed UTF-8 locale, e.g. {{ic|<nowiki>LANG=nn_NO.utf8</nowiki>}}.
 
If you start subsonic using {{ic|/etc/rc.d/subsonic}}, and your /etc/[[rc.conf]] has {{ic|<nowiki>DAEMON_LOCALE="no"</nowiki>}}, then the subsonic daemon will be started with the C locale, and Java will skip any folders with "international characters" (e.g. ßðþøæå etc.). Either set {{ic|DAEMON_LOCALE}} to {{ic|"yes"}} (but this will affect '''all''' rc.daemons), or add a line to the beginning of {{ic|/var/subsonic/subsonic.sh}} which sets {{ic|LANG}} to an installed UTF-8 locale, e.g. {{ic|<nowiki>LANG=nn_NO.utf8</nowiki>}}.
 +
 +
===Accessing the database===
 +
 +
Subsonic stores all its data inside a [http://hsqldb.org/ HyperSQL] database in {{ic|/var/lib/subsonic/db}}. You can access it with a simple web interface by going to http://localhost:4040/db.view (replace with your Subsonic URL).
 +
 +
You can also use the SQLTool command-line tool from the HyperSQL distribution, found in {{aur|hsqldb2-java}}. Note that this tool cannot be run concurrently with your Subsonic instance, so you will have to either shut it down or copy the database directory.
 +
 +
SQLTool first needs a {{ic|~/sqltool.rc}} file with the following contents :
 +
 +
{{bc|
 +
urlid subsonic
 +
url jdbc:hsqldb:/var/lib/subsonic/db/subsonic
 +
username sa
 +
password}}
 +
 +
Then, you can for example export all the contents in the {{ic|MEDIA_FILE}} table :
 +
 +
{{bc|
 +
$ java -jar /usr/share/java/sqltool.jar subsonic - <<< '\xq MEDIA_FILE'
 +
8074 row(s) fetched from database.
 +
Wrote 3252295 characters to file 'MEDIA_FILE.csv'.}}
 +
 +
==Madsonic==
 +
Madsonic is a (non-free) fork of Subsonic with extra features and is available in AUR.
 +
 +
Once you start the server, pay close attention to the Transcoding options, as you will probably have to change the command from "Audioffmpeg" to "ffmpeg".
  
 
==External links==
 
==External links==
 
* [http://www.subsonic.org Official web site]
 
* [http://www.subsonic.org Official web site]

Latest revision as of 22:34, 2 May 2016

Subsonic is a music server that lets you store your music on one machine and play it from other machines, cell phones, via a web interface, or various other applications. It can be installed using the subsonicAUR package on AUR. As of version 6, the software is not open source anymore.

Configuration

After performing any configuration, remember to restart subsonic.service.

Install transcoders

By default, Subsonic uses FFmpeg to transcode videos and songs to an appropriate format and bitrate on-the-fly. After installation, you can change these defaults so that, for example, Subsonic will transcode FLAC files using FLAC and LAME instead of FFmpeg. You should therefore Install the ffmpeg, and you may also want to install flac and lame.

For security reasons, Subsonic will not search the system for any transcoders. Instead, the user must create symlinks to the transcoders in the /var/lib/subsonic/transcode folder. Create the symlinks like so:

$ cd /var/lib/subsonic/transcode
# for transcoder in ffmpeg flac lame; do ln -s "$(which $transcoder)"; done

HTTPS Setup

With Subsonic

To enable HTTPS browsing and streaming, edit /var/lib/subsonic/subsonic.sh and change this line:

SUBSONIC_HTTPS_PORT=0

To this:

SUBSONIC_HTTPS_PORT=8443
Note: port 8443 seems hard-coded somewhere. When attempting to change it to port 8080 it will automatically redirect the browser to port 8443 after manually accepting the invalid HTTPS certificate. You will still be able to re-navigate to port 8080 after the warning page and have it work on that port.

With Nginx

If you already have multiple web services running, it might be easier to use a single SSL configuration everywhere. The following Nginx configuration runs Subsonic under https://example.com/subsonic :

server {
    listen              443 default ssl;
    server_name         example.com;
    ssl_certificate     cert.pem
    ssl_certificate_key key.pem

    location /subsonic {
      proxy_set_header X-Real-IP         $remote_addr;
      proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header Host              $http_host;
      proxy_max_temp_file_size           0;
      proxy_pass                         http://127.0.0.1:4040;
      proxy_redirect                     http:// https://;
    }
} 

To run Subsonic under a different path, you have to set the following options in /var/lib/subsonic/subsonic.sh :

SUBSONIC_CONTEXT_PATH=/subsonic
SUBSONIC_HOST=127.0.0.1
SUBSONIC_PORT=4040
SUBSONIC_HTTPS_PORT=0

Troubleshooting

FLAC playback

The FFmpeg transcoder doesn't handle FLAC files well, and clients will often fail to play the resultant streams. (at least, on my machine) Using FLAC and LAME instead of FFmpeg solves this issue. This workaround requires that the FLAC and LAME transcoders have been installed, as explained in #Install transcoders.

Start Subsonic and go to settings > transcoding. Ensure that the default FFmpeg transcoder does not get used on files with a "flac" extension, then add a new entry. You'll end up with something like this:

Name Convert from Convert to Step 1 Step 2
mp3 default ... NOT flac ... mp3 ffmpeg ...  
mp3 flac flac mp3 flac --silent --decode --stdout %s lame --silent -h -b %b -

UTF-8 file names not added to the database

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: The default init system under Arch is now Systemd, not SysV. (Discuss in Talk:Subsonic#)

You must have at least one UTF-8 locale installed.

If you start subsonic using /etc/rc.d/subsonic, and your /etc/rc.conf has DAEMON_LOCALE="no", then the subsonic daemon will be started with the C locale, and Java will skip any folders with "international characters" (e.g. ßðþøæå etc.). Either set DAEMON_LOCALE to "yes" (but this will affect all rc.daemons), or add a line to the beginning of /var/subsonic/subsonic.sh which sets LANG to an installed UTF-8 locale, e.g. LANG=nn_NO.utf8.

Accessing the database

Subsonic stores all its data inside a HyperSQL database in /var/lib/subsonic/db. You can access it with a simple web interface by going to http://localhost:4040/db.view (replace with your Subsonic URL).

You can also use the SQLTool command-line tool from the HyperSQL distribution, found in hsqldb2-javaAUR. Note that this tool cannot be run concurrently with your Subsonic instance, so you will have to either shut it down or copy the database directory.

SQLTool first needs a ~/sqltool.rc file with the following contents :

urlid subsonic
url jdbc:hsqldb:/var/lib/subsonic/db/subsonic
username sa
password

Then, you can for example export all the contents in the MEDIA_FILE table :

$ java -jar /usr/share/java/sqltool.jar subsonic - <<< '\xq MEDIA_FILE'
8074 row(s) fetched from database.
Wrote 3252295 characters to file 'MEDIA_FILE.csv'.

Madsonic

Madsonic is a (non-free) fork of Subsonic with extra features and is available in AUR.

Once you start the server, pay close attention to the Transcoding options, as you will probably have to change the command from "Audioffmpeg" to "ffmpeg".

External links