You are not logged in.

#1 2014-11-22 17:13:20

alv-r-
Member
Registered: 2014-11-22
Posts: 2

Problem with user services (creating a service for mpdas)

Hi, I'm using mpd and using a user service to start it.
However, I'm trying to create a service for mpdas (a mpd client for last.fm) and getting some errors:

currently, my mpdas.service is as following:

[Unit]
Description=AudoScrobbler client for MPD
After=mpd.service

[Service]
ExecStart=/usr/bin/mpdas

[Install]
WantedBy=default.target

Which giving me the following errors:

(14:49:55) [ERROR] You are not root. Not changing user ..
(14:49:55) [INFO] Connected to MPD.
(14:49:56) [INFO] Last.fm handshake successful. SessionID: ...
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file
Aborted

Which are the same errors I get if I run just "mpdas" instead of running it with sudo.

If I use it as a root service (instead of a user service) it fails on startup, but works fine when I restart the server.
So, I'm assuming:
1) mpdas needs root permission
2) if used as a root service, it fails at startup cause the mpd service (enabled as a user service) hasn't started yet
3) if used as a user service, it fails cause it needs root permission

What's the 'correct' way to solve this? (I believe mpdas should be a user service, cause it runs with a config that is just for my user).
Is there a way to make a user service run with root privileges?
I couldn't figure out the best way to configure it.

Last edited by alv-r- (2014-11-29 18:37:56)

Offline

#2 2014-11-22 17:40:13

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,536

Re: Problem with user services (creating a service for mpdas)

Why should it fails with sudo?
Doesn't it works with fakeroot ?


do it good first, it will be faster than do it twice the saint wink

Offline

#3 2014-11-22 19:28:07

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Problem with user services (creating a service for mpdas)

Why does it need root privileges? Maybe you just need to configure it properly to run under your normal user?

Offline

#4 2014-11-29 18:12:52

alv-r-
Member
Registered: 2014-11-22
Posts: 2

Re: Problem with user services (creating a service for mpdas)

TheSaint wrote:

Why should it fails with sudo?

It works only with sudo. It was failing as a system service because it needs mpd, which I configured as an user service. Then when systemd starts the system services (when booting) there's not mpd instance running and it fails.

TheSaint wrote:

Doesn't it works with fakeroot ?

As a noob, I don't know exactly how fakeroot works, I'll take a better look at it, but running it with fakeroot takes rid of the errors I was getting when not running as sudo.

The problem I have now is that it still fails on startup, but there isn't any helpful (or unhelpful) message. It just shows the PID and says it failed.
If I run

systemctl --user start mpdas

it works well though. Any ideas of why this happens?

My current unit file looks like this:

[Unit]
Description=AudoScrobbler client for MPD
After=mpd.service
Requires=mpd.service

[Service]
ExecStart=/usr/bin/fakeroot /usr/bin/mpdas

[Install]
WantedBy=default.target
Raynman wrote:

Why does it need root privileges? Maybe you just need to configure it properly to run under your normal user?

Seeing the options in the man page and the config options for the config file, I don't see any that could do the trick.
I'll send a message to the developer with the error I'm getting (when not running as sudo).

Last edited by alv-r- (2014-11-29 18:36:59)

Offline

#5 2016-02-10 06:41:24

ShionjiYuuko
Member
Registered: 2011-07-31
Posts: 67

Re: Problem with user services (creating a service for mpdas)

I encountered the same problem too.

It does not need root permission. You can run it as daemon user or ordinary user.
However, it expects that MPD server already running and responding. From systemd standpoint this requirement is already fulfilled but MPD has not actually been started or already running but not yet ready to listen. In other words, it starts too early.
The solution might be replacing mpdas service with a script that starts the real mpdas service after certain amount of time.


始まりの荒野を独り もう歩き出してるらしい、僕は灰になるまで僕で有り続けたい
http://about.me/nnhnkn | http://identi.ca/nnhzkn

Offline

#6 2016-02-10 06:49:47

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Problem with user services (creating a service for mpdas)


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB