Spotifyd/spotifyd

Can't enable service: Failed to enable unit: Unit file /etc/systemd/system/default.target.wants/spotifyd.service does not exist.

tomyo opened this issue · 12 comments

tomyo commented

Description
When I follow the instructions here https://spotifyd.github.io/spotifyd/config/services/Systemd.html#as-a-system-wide-service:

  1. I copy the service file in /etc/systemd/system/.
  2. Run
  • # systemctl daemon-reload
  • # systemctl enable spotifyd.service --now
  1. Get: Failed to enable unit: Unit file /etc/systemd/system/default.target.wants/spotifyd.service does not exist.

Expected behavior
Service starts

Versions (please complete the following information):

spotifyd 0.3.3

Additional context
Running NixOS, installed as described here: https://search.nixos.org/packages?channel=22.05&show=spotifyd&from=0&size=50&sort=relevance&type=packages&query=spotifyd

What am I missing?

Thank you, nice app!

That page seems to describe using nix-shell — doesn't that not actually install it? I thought nix-shell was a temporary workspace type thing.

To clarify my comment somewhat: I'm pretty sure we don't maintain the Nix package in-house, so my first thought if you installed it and aren't seeing the systemd service file is that something related to the Nix package is not doing what would be expected.

As long as the nix package is bringing in a compiled binary to your path, adding the systemd service separately is okay (imo). You can check this with which spotifyd If it's not on your path the package is broken.

As a note I'd recommend the user service if you have no preference.

First, check that the unit file is in either
/etc/systemd/user/ ( I think you placed the service in system, not user)
~/.config/systemd/user

Second, I'd try running as sudo for system-wide configuration, it may just be a permissions issue preventing systemd from finding the file.

As a final resort you could just drop the service file in
/etc/systemd/system/default.target.wants/
but user defined services should really go in a user designated folder

Hey, I have the some different issue. I've copied spotifyd.service to ~/.config/systemd/user:

ll  ~/.config/systemd/user
total 8
drwxr-xr-x. 1 krp krp  82 гру 23 12:29 default.target.wants
drwxr-xr-x  1 krp krp  38 лис  4  2021 pipewire.service.wants
lrwxrwxrwx  1 krp krp  41 лис  4  2021 pipewire-session-manager.service -> /usr/lib/systemd/user/wireplumber.service
-rwxr--r--  1 krp krp 305 гру 23 12:27 spotifyd.service

Also I've setup config file ~/.config/spotifyd/spotifyd.conf:

username = ***************
password = ***************

# A command that gets executed and can be used to
# retrieve your password.
# The command should return the password on stdout.
#
# This is an alternative to the `password` field. Both
# can't be used simultaneously.
#password_cmd = "command_that_writes_password_to_stdout"

# If set to true, `spotifyd` tries to look up your
# password in the system's password storage.
#
# This is an alternative to the `password` field. Both
# can't be used simultaneously.
#use_keyring = true

# If set to true, `spotifyd` tries to bind to dbus (default is the session bus)
# and expose MPRIS controls. When running headless, without the session bus,
# you should set this to false, to avoid errors. If you still want to use MPRIS,
# have a look at the `dbus_type` option.
use_mpris = true

# The bus to bind to with the MPRIS interface.
# Possible values: "session", "system"
# The system bus can be used if no graphical session is available
# (e.g. on headless systems) but you still want to be able to use MPRIS.
# NOTE: You might need to add appropriate policies to allow spotifyd to
# own the name.
dbus_type = "session"

# The audio backend used to play music. To get
# a list of possible backends, run `spotifyd --help`.
backend = "alsa" # use portaudio for macOS [homebrew]

# The alsa audio device to stream audio. To get a
# list of valid devices, run `aplay -L`,
device = "alsa_audio_device"  # omit for macOS

# The alsa control device. By default this is the same
# name as the `device` field.
control = "alsa_audio_device"  # omit for macOS

# The alsa mixer used by `spotifyd`.
mixer = "PCM"  # omit for macOS

# The volume controller. Each one behaves different to
# volume increases. For possible values, run
# `spotifyd --help`.
volume_controller = "alsa"  # use softvol for macOS

# A command that gets executed in your shell after each song changes.
on_song_change_hook = "command_to_run_on_playback_events"

# The name that gets displayed under the connect tab on
# official clients. Spaces are not allowed!
device_name = "fedora-krp"

# The audio bitrate. 96, 160 or 320 kbit/s
bitrate = 160

# The directory used to cache audio data. This setting can save
# a lot of bandwidth when activated, as it will avoid re-downloading
# audio files when replaying them.
#
# Note: The file path does not get expanded. Environment variables and
# shell placeholders like $HOME or ~ don't work!
cache_path = "/home/krp/Music/SpotifyCache"

# The maximal size of the cache directory in bytes
# The example value corresponds to ~ 1GB
max_cache_size = 1000000000

# If set to true, audio data does NOT get cached.
no_audio_cache = true

# Volume on startup between 0 and 100
# NOTE: This variable's type will change in v0.4, to a number (instead of string)
initial_volume = "30"

# If set to true, enables volume normalisation between songs.
volume_normalisation = true

# The normalisation pregain that is applied for each song.
normalisation_pregain = -10

# After the music playback has ended, start playing similar songs based on the previous tracks.
autoplay = true

# The port `spotifyd` uses to announce its service over the network.
zeroconf_port = 1234

# The proxy `spotifyd` will use to connect to spotify.
proxy = "http://proxy.example.org:8080"

# The displayed device type in Spotify clients.
# Can be unknown, computer, tablet, smartphone, speaker, t_v,
# a_v_r (Audio/Video Receiver), s_t_b (Set-Top Box), and audio_dongle.
device_type = "speaker"

And as result of starting have an error:

 krp  ~  systemctl --user status spotifyd.service
● spotifyd.service - A spotify playing daemon
     Loaded: loaded (/home/krp/.config/systemd/user/spotifyd.service; enabled; preset: disabled)
     Active: activating (auto-restart) (Result: exit-code) since Fri 2022-12-23 13:26:41 EET; 8s ago
       Docs: https://github.com/Spotifyd/spotifyd
    Process: 73138 ExecStart=/home/krp/.cargo/bin/spotifyd (code=exited, status=1/FAILURE)
   Main PID: 73138 (code=exited, status=1/FAILURE)
        CPU: 6ms

гру 23 13:26:41 localhost.localdomain systemd[14740]: spotifyd.service: Failed with result 'exit-code'.

Here additional info:

 krp  ~  3  which spotifyd 
/home/krp/.cargo/bin/spotifyd

~/.config/systemd/user/spotifyd.service

[Unit]
Description=A spotify playing daemon
Documentation=https://github.com/Spotifyd/spotifyd
Wants=sound.target
After=sound.target
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/home/krp/.cargo/bin/spotifyd
Restart=always
RestartSec=12

[Install]
WantedBy=default.target

@bigkrp You should specify --no-daemon in the ExecStart option as it is done here. Then you should be able to see logs of what's failing here.

Here output

 krp  ~  systemctl --user status spotifyd.service --now
● spotifyd.service - A spotify playing daemon
     Loaded: loaded (/home/krp/.config/systemd/user/spotifyd.service; enabled; preset: disabled)
     Active: activating (auto-restart) (Result: exit-code) since Mon 2023-01-02 10:03:02 EET; 3s ago
       Docs: https://github.com/Spotifyd/spotifyd
    Process: 14713 ExecStart=/home/krp/.cargo/bin/spotifyd --no-daemon (code=exited, status=1/FAILURE)
   Main PID: 14713 (code=exited, status=1/FAILURE)
        CPU: 2ms

січ 02 10:03:02 localhost.localdomain systemd[3348]: spotifyd.service: Main process exited, code=exited, status=1/FAILURE
січ 02 10:03:02 localhost.localdomain systemd[3348]: spotifyd.service: Failed with result 'exit-code'.

Or you mean, I need see logs somewhere else?

@bigkrp to clarify eladyn's comment:
spotifyd has a cli option --no-daemon (a daemon is a background process). Your systemd-service file should use this option so you can view it's output in systemctl (else systemd can't log it). Look at his eladyn's linked file under header [service].

I use this option to manually launch spotifyd when debugging any installation issues. I'd recommend trying to manually launch spotifyd successfully before you debug any systemd issues.

I tried run it and have two errors:

 krp  ~  Projects  which spotifyd
/home/krp/.cargo/bin/spotifyd
 krp  ~  Projects  vim /home/krp/.cargo/bin/spotifyd
 krp  ~  Projects  /home/krp/.cargo/bin/spotifyd
Error: 
   0: could not load the config file
   1: invalid TOML value, did you mean to use a quoted string? at line 1 column 12

Location:
   /home/krp/.cargo/registry/src/github.com-1ecc6299db9ec823/spotifyd-0.3.4/src/config.rs:531

note:
   the config format should be valid TOML
   we recently changed the config format, see https://github.com/Spotifyd/spotifyd/issues/765

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

@bigkrp The error tells you what's going wrong. You should check your configuration file (usually under ~/.config/spotifyd/spotifyd.conf) and make sure that it's valid TOML. See here for an example config file.

Yeah it was problem of not-valid config, because I've written username and password values without quotes.
Now it seems started well, but I cant see it in my devices for example in spt

According to my config it should be device_name = "fedora-krp"

Any idea how can I manage with this issue?

@bigkrp Hmm, without further context, it's difficult to tell. Does spotifyd log anything interesting (potentially in --verbose mode)? Are you using the same account for spotifyd that you're using within spt?

I'm going to close this for now. If you have any further unresolved questions, you can either create a (freshly enabled) discussion or hop on the matrix channel and we'll see how we can help you.