Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config file in /etc/defaults doesn't allow user to be changed for systemd script #791

Closed
tremby opened this issue Feb 5, 2021 · 5 comments
Labels
bug next release fixed in develop branch and will be part of the next release

Comments

@tremby
Copy link

tremby commented Feb 5, 2021

Describe the bug
Though the package seems to have installed both /etc/init.d/snapclient and /lib/systemd/system/snapclient.service it seems to be only the latter which does something. I get weird issues with multiple pulseaudio servers if snapclient doesn't run as my interactive user, so I want it to start as me. But I can't seem to configure it that way via the intended /etc/default/snapclient file.

The file /etc/init.d/snapclient was a big red herring here; I was trying to debug via that file but it wasn't even being invoked. Took me a while to realize there was a separate systemd unit. START_SNAPCLIENT doesn't seem to have any effect either; it's not referenced in the systemd file. Perhaps some comments in there would help with this confusion.

Steps to Reproduce

  1. In /etc/default/snapclient, set --user tremby:tremby in SNAPCLIENT_OPTS
  2. Restart the service with sudo systemctl restart snapclient
  3. Look at ps output, see that it was still started as snapclient, even though it does have the new options present

Environment details

  • OS: Ubuntu
  • Snapcast version develop at 2c0703e
  • Installed from Debian amd64 package

I've edited the systemd script's user and group entries for now, but this config is surely supposed to be done in the defaults file.

@tremby tremby added the bug label Feb 5, 2021
@tremby
Copy link
Author

tremby commented Feb 5, 2021

Though I still think this is valid, I just found out how to allow other system users access to my main user's pulse server, by following this guide:

http://billauer.co.il/blog/2014/01/pa-multiple-users/

And so now I'm running snapclient as the snapclient user again.

@badaix
Copy link
Owner

badaix commented Feb 13, 2021

the user setting will only be applied when Snapclient is running as daemon, see snapclient -h:

--user arg                      the user[:group] to run snapclient as when daemonized

The init script will run Snapclient as daemon, what is usual for init.d processes: init.d will just launch a script as root and the script will launch the process, also running as root. The process then forkes itself with a different user (the configured one) and the root process will finish itself.
Systemd is more modern and allows to configure the user within the unit file, there is no need for forking. Forking is even counterproductive, because systemd will observe and restart the process if it dies, for old processes that fork itself Systemd cannot rely on the pid, but uses heuristics to find out that the process didn't die.
Regarding systemd and init.d scripts: the official debain packages also install both, so it seems to be ok, I'm not an expert in this field.
Long story short: it's at most a documentation issue, but everything is working as intended.

@badaix badaix closed this as completed Feb 13, 2021
@tremby
Copy link
Author

tremby commented Feb 14, 2021

OK, I see. Yeah, I think better comments in those two files would go a long way! If the /etc/default/snapclient file only affects one of the two scripts that'd be good to note, for example.

@badaix badaix reopened this Feb 14, 2021
@badaix
Copy link
Owner

badaix commented Feb 14, 2021

It will affact both, systemd and init.d:

init.d

...
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
SNAPCLIENT_OPTS="--daemon --logsink=system --user $USERNAME:$USERNAME $SNAPCLIENT_OPTS"
...

systemd

...
[Service]
EnvironmentFile=-/etc/default/snapclient
ExecStart=/usr/bin/snapclient --logsink=system $SNAPCLIENT_OPTS
...

The --deamon for init.d makes the difference. It will let Snapclient actually use the --user option.
I will add a note to the /etc/default/snapclient file.

@xabolcs
Copy link
Contributor

xabolcs commented Feb 14, 2021

Hi @tremby !

I get weird issues with multiple pulseaudio servers if snapclient doesn't run as my interactive user, so I want it to start as me.

I did the following modifications to my outdated Snapclient v0.20.0 to run as my user:
I copied the .service file to my $HOME specific systemd directory, and unset the User= and Group= options.

--- /lib/systemd/system/snapclient.service	2020-06-11 13:27:52.000000000 +0200
+++ $HOME/.config/systemd/user/snapclient.service	2020-07-29 12:20:09.952184944 +0200
@@ -2,14 +2,14 @@
 Description=Snapcast client
 Documentation=man:snapclient(1)
 Wants=avahi-daemon.service
 After=network-online.target time-sync.target sound.target avahi-daemon.service
 
 [Service]
 EnvironmentFile=-/etc/default/snapclient
 ExecStart=/usr/bin/snapclient --logsink=system $SNAPCLIENT_OPTS
-User=snapclient
-Group=snapclient
+#User=snapclient
+#Group=snapclient
 Restart=on-failure
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=default.target

I use it with --user: systemctl --user status snapclient and systemctl --user start snapclient

$ systemctl --user status snapclient.service 
● snapclient.service - Snapcast client
   Loaded: loaded ($HOME/.config/systemd/user/snapclient.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-02-14 17:50:37 CET; 2s ago
     Docs: man:snapclient(1)
 Main PID: 12554 (snapclient)
   CGroup: /user.slice/user-1001.slice/[email protected]/snapclient.service
           └─12554 /usr/bin/snapclient --logsink=system -s 2

@badaix badaix added the next release fixed in develop branch and will be part of the next release label Feb 14, 2021
@badaix badaix closed this as completed Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug next release fixed in develop branch and will be part of the next release
Projects
None yet
Development

No branches or pull requests

3 participants