badaix / snapcast

Synchronous multiroom audio player
GNU General Public License v3.0
6.21k stars 456 forks source link

Snapserver service won't start #1231

Closed seth-hoisington closed 6 months ago

seth-hoisington commented 6 months ago

Hi,

I am getting an error which causes the snapserver systemd service to crash. I am running Raspbian Bookworm (up to date as of 5/2/2024) on a Raspberry Pi 5. I have looked into past issues, but unlike those issues, it seems that my user/group permissions are correct. Snapserver works when I run sudo snapserver, but the service stubbornly refuses to afford me the same courtesy. Here are my logs:

Systemctl status (sudo systemctl status snapserver):

x snapserver.service - Snapcast server
     Loaded: loaded (/lib/systemd/system/snapserver.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-05-02 14:55:38 CDT; 4h 42min ago
   Duration: 6ms
       Docs: man:snapserver(1)
    Process: 3495 ExecStart=/usr/bin/snapserver --logging.sink=system --server.datadir=${HOME} $SNAPSERVER_OPTS (code=exited, status=1/FAILUR>
   Main PID: 3495 (code=exited, status=1/FAILURE)
        CPU: 6ms

May 02 14:55:38 sethpi systemd[1]: snapserver.service: Scheduled restart job, restart counter is at 5.
May 02 14:55:38 sethpi systemd[1]: Stopped snapserver.service - Snapcast server.
May 02 14:55:38 sethpi systemd[1]: snapserver.service: Start request repeated too quickly.
May 02 14:55:38 sethpi systemd[1]: snapserver.service: Failed with result 'exit-code'.
May 02 14:55:38 sethpi systemd[1]: Failed to start snapserver.service - Snapcast server.

Error message in systemd journal (sudo journalctl -u snapserver):

May 02 14:55:38 sethpi snapserver[3495]: Settings file: "/var/lib/snapserver/server.json"
May 02 14:55:38 sethpi snapserver[3495]: Exception: failed to open file "/var/lib/snapserver/server.json", permission denied (error 13)
May 02 14:55:38 sethpi snapserver[3495]: Snapserver terminated.

Systemd unit file:

[Unit]
Description=Snapcast server
Documentation=man:snapserver(1)
Wants=avahi-daemon.service
After=network-online.target time-sync.target avahi-daemon.service

[Service]
EnvironmentFile=-/etc/default/snapserver
ExecStart=/usr/bin/snapserver --logging.sink=system --server.datadir=${HOME} $SNAPSERVER_OPTS
User=snapserver
Group=snapserver
Restart=on-failure

[Install]
WantedBy=multi-user.target

Unit file permissions (ls -l /var/lib/snapserver/server.json):

-rw-r--r-- 1 snapserver snapserver 31 May  2 14:10 /var/lib/snapserver/server.json

Configs: /etc/default/snapserver:

SNAPSERVER_OPTS=""
START_SNAPSERVER=true

/etc/snapserver.conf:

###############################################################################
#     ______                                                                  #
#    / _____)                                                                 #
#   ( (____   ____   _____  ____    ___  _____   ____  _   _  _____   ____    #
#    \____ \ |  _ \ (____ ||  _ \  /___)| ___ | / ___)| | | || ___ | / ___)   #
#    _____) )| | | |/ ___ || |_| ||___ || ____|| |     \ V / | ____|| |       #
#   (______/ |_| |_|\_____||  __/ (___/ |_____)|_|      \_/  |_____)|_|       #
#                          |_|                                                #
#                                                                             #
#  Snapserver config file                                                     #
#                                                                             #
###############################################################################

# default values are commented
# uncomment and edit to change them

# Settings can be overwritten on command line with:
#  "--<section>.<name>=<value>", e.g. --server.threads=4

# General server settings #####################################################
#
[server]
# Number of additional worker threads to use
# - For values < 0 the number of threads will be 2 (on single and dual cores)
#   or 4 (for quad and more cores)
# - 0 will utilize just the processes main thread and might cause audio drops 
#   in case there are a couple of longer running tasks, such as encoding 
#   multiple audio streams
#threads = -1

# the pid file when running as daemon
#pidfile = /var/run/snapserver/pid

# the user to run as when daemonized
#user = snapserver
# the group to run as when daemonized
#group = snapserver

# directory where persistent data is stored (server.json)
# if empty, data dir will be
#  - "/var/lib/snapserver/" when running as daemon
#  - "$HOME/.config/snapserver/" when not running as daemon
#datadir = 

#
###############################################################################

# HTTP RPC ####################################################################
#
[http]
# enable HTTP Json RPC (HTTP POST and websockets)
enabled = true
doc_root = /home/seth/snapweb
# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
bind_to_address = 0.0.0.0

# which port the server should listen to
port = 1780

# serve a website from the doc_root location
# disabled if commented or empty
# doc_root = /usr/share/snapserver/snapweb

# Hostname or IP under which clients can reach this host
# used to serve cached cover art
# use <hostname> as placeholder for your actual host name  
#host = <hostname>

#
###############################################################################

# TCP RPC #####################################################################
#
[tcp]
# enable TCP Json RPC
#enabled = true

# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
#bind_to_address = 0.0.0.0

# which port the server should listen to
#port = 1705
#
###############################################################################

# Stream settings #############################################################
#
[stream]
# address to listen on, can be specified multiple times
# use "0.0.0.0" to bind to any IPv4 address or :: to bind to any IPv6 address
# or "127.0.0.1" or "::1" to bind to localhost IPv4 or IPv6, respectively
# use the address of a specific network interface to just listen to and accept
# connections from that interface
#bind_to_address = 0.0.0.0

# which port the server should listen to
#port = 1704

# source URI of the PCM input stream, can be configured multiple times
# The following notation is used in this paragraph:
#  <angle brackets>: the whole expression must be replaced with your specific setting
# [square brackets]: the whole expression is optional and can be left out
# [key=value]: if you leave this option out, "value" will be the default for "key"
#
# Format: TYPE://host/path?name=<name>[&codec=<codec>][&sampleformat=<sampleformat>][&chunk_ms=<chunk ms>][&controlscript=<control script filename>]
#  parameters have the form "key=value", they are concatenated with an "&" character
#  parameter "name" is mandatory for all sources, while codec, sampleformat and chunk_ms are optional
#  and will override the default codec, sampleformat or chunk_ms settings
# Non blocking sources support the dryout_ms parameter: when no new data is read from the source, send silence to the clients
# Available types are:
# pipe: pipe:///<path/to/pipe>?name=<name>[&mode=create][&dryout_ms=2000], mode can be "create" or "read"
# librespot: librespot:///<path/to/librespot>?name=<name>[&dryout_ms=2000][&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&wd_timeout=7800][&volume=100][&onevent=""][&nomalize=false][&autoplay=false][&params=<generic librepsot process arguments>]
#  note that you need to have the librespot binary on your machine
#  sampleformat will be set to "44100:16:2"
# file: file:///<path/to/PCM/file>?name=<name>
# process: process:///<path/to/process>?name=<name>[&dryout_ms=2000][&wd_timeout=0][&log_stderr=false][&params=<process arguments>]
# airplay: airplay:///<path/to/airplay>?name=<name>[&dryout_ms=2000][&port=5000]
#  note that you need to have the airplay binary on your machine
#  sampleformat will be set to "44100:16:2"
# tcp server: tcp://<listen IP, e.g. 127.0.0.1>:<port>?name=<name>[&mode=server]
# tcp client: tcp://<server IP, e.g. 127.0.0.1>:<port>?name=<name>&mode=client
# alsa: alsa://?name=<name>&device=<alsa device>[&send_silence=false][&idle_threshold=100][&silence_threshold_percent=0.0]
# meta: meta:///<name of source#1>/<name of source#2>/.../<name of source#N>?name=<name>

#source = pipe:///tmp/snapfifo?name=default
#source = tcp://127.0.0.1?name=mopidy_tcp
source = librespot:////home/seth/.cargo/bin/librespot?name=Spotify&dryout_ms=2000&devicename=HomeAudio
#source = airplay:////usr/local/bin/shairport-sync?name=Airplay
#source = pipe:///tmp/snapfifo?name=Radio
#source = pipe:///tmp/snapfifi?name=Madio

# Default sample format: <sample rate>:<bits per sample>:<channels>
sampleformat = 44100:16:2

# Default transport codec
# (flac|ogg|opus|pcm)[:options]
# Start Snapserver with "--stream:codec=<codec>:?" to get codec specific options
#codec = flac

# Default source stream read chunk size [ms]. 
# The server will continously read this number of milliseconds from the source into buffer and pass this buffer to the encoder.
# The encoded buffer is sent to the clients. Some codecs have a higher latency and will need more data, e.g. Flac will need ~26ms chunks
#chunk_ms = 20

# Buffer [ms]
# The end-to-end latency, from capturing a sample on the server until the sample is played-out on the client
buffer = 2000

# Send audio to muted clients
#send_to_muted = false
#
###############################################################################

# Logging options #############################################################
#
[logging]

# log sink [null,system,stdout,stderr,file:<filename>]
# when left empty: if running as daemon "system" else "stdout"
#sink = 

# log filter <tag>:<level>[,<tag>:<level>]* 
# with tag = * or <log tag> and level = [trace,debug,info,notice,warning,error,fatal]
#filter = *:info
#
###############################################################################
badaix commented 6 months ago

Who's the owner of /var/lib/snapserver/server.json? If you had previously installed snapcast from the official debian repo then it will use a different user as the packages provides in this repo. (user snapcast vs snapcast_). You can apt purge snapserver to not only uninstall snapserver, but also remove all configuration files and do a clean install after purging.

seth-hoisington commented 6 months ago

Who's the owner of /var/lib/snapserver/server.json? If you had previously installed snapcast from the official debian repo then it will use a different user as the packages provides in this repo. (user snapcast vs snapcast_). You can apt purge snapserver to not only uninstall snapserver, but also remove all configuration files and do a clean install after purging.

Thanks for the quick reply. This worked! Thank you for all the work you do!

MorrisekN commented 4 months ago

Hello! I have been trying to install Snapserver on my Raspberry pi 400 for 3 days now. I am faced with the same problem every time. `× snapserver.service - Snapcast server Loaded: loaded (/lib/systemd/system/snapserver.service; enabled; preset: enabled) Active: failed (Result: exit-code) since Mon 2024-07-08 17:02:41 BST; 13min ago Duration: 28ms Docs: man:snapserver(1) Process: 1865 ExecStart=/usr/bin/snapserver --logging.sink=system --server.datadir=${HOME} $SNAPSERVER_OPTS (code=exited, status=1/FAILURE) Main PID: 1865 (code=exited, status=1/FAILURE) CPU: 27ms

Jul 08 17:02:41 raspberrypi systemd[1]: snapserver.service: Scheduled restart job, restart counter is at 5. Jul 08 17:02:41 raspberrypi systemd[1]: Stopped snapserver.service - Snapcast server. Jul 08 17:02:41 raspberrypi systemd[1]: snapserver.service: Start request repeated too quickly. Jul 08 17:02:41 raspberrypi systemd[1]: snapserver.service: Failed with result 'exit-code'. Jul 08 17:02:41 raspberrypi systemd[1]: Failed to start snapserver.service - Snapcast server. ` I also reinstalled the system, but it didn't help. I installed mopids, pulse audio and the latest version of the server. Ultimately, I want to install snapclient on the same device so that it can connect to the Bluetooth speaker. Help, please...