Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rc init per user: I still don't understand...
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
sixtysixtysix
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jun 2021
Posts: 86

PostPosted: Mon Sep 20, 2021 4:03 pm    Post subject: rc init per user: I still don't understand... Reply with quote

Noob question here but honestly, I STILL cannot find a direct answer, despite I read the wiki carefully. The description there was a bit too brief for me...

I have a simple issue: I want my mpd instance to start as user (me) once I log in. I understood the bit about NOT invoking as root but quite honestly I still have zero idea of how I have a service start under rc_init "per user" as opposed to root.

It must be such a simple thing - would someone please be kind enough to provide an easy to follow full explanation? If possible I'd like it at login not on reboot, as obviously it's more common to log out (switch user) than to reboot.

Many thanks :)
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9679
Location: almost Mile High in the USA

PostPosted: Mon Sep 20, 2021 4:11 pm    Post subject: Reply with quote

There are lots of ways to do this depending on what you use to login and the nature of the program.
1. Go to your desktop environment settings and add an "startup script" - usually the best option if you run a DE.
2. Add a line to your Xinit or Xsession if you use these - can break other stuff if you're not careful
3. Add a line into your shell startup like .bash_login, .login, .profile, etc. - does not work for things that require guis

Remember you may need to kill the process on logout or make sure you don't run it again so scripting may be necessary.

Sure you don't want to start during system startup? You can use 'su' to run it as a different user.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
sixtysixtysix
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jun 2021
Posts: 86

PostPosted: Mon Sep 20, 2021 4:18 pm    Post subject: Reply with quote

Thank you for this :)

To be honest I think I'd gotten a bit lost in all the documentation - clearly adding a startup option for stuff in my DE is something I already do. Doh!

So, in the interests of further understanding: this being simply to have mpd running and available for whenever I might choose to start my media player (Cantata by choice), I wasn't aware that I could have mpd start at boot and yet NOT be run as root. Any further explanations welcome, but for now yes sure, I can simply add another start option to my DE.

BTW I chose to skip any login process, so while I run XFCE it boots directly to the desktop. Being the only user it seems daft having to keep entering a password.

Many thanks :)
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30917
Location: here

PostPosted: Mon Sep 20, 2021 4:23 pm    Post subject: Reply with quote

mpd openrc init script run as mpd user and audio group.
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
sixtysixtysix
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jun 2021
Posts: 86

PostPosted: Mon Sep 20, 2021 4:30 pm    Post subject: Reply with quote

fedeliallalinea wrote:
mpd openrc init script run as mpd user and audio group.


while I realise that this is offered in a spirit of helpfulness, unfortunately it's exactly this kind of extreme brevity that has led to my current lack of understanding.

I simply don't understand what "init script run as mpd user" is supposed to mean! I get that one SHOULD NOT run mpd as root... so...

If I run it under my login, I'm already a member of audio group.

Not trying to be in the slightest bit mean or unduly critical, but the above feels to me like everything the wiki has told me NOT to do... but again, I'm asking for help because I don't understand :)
Back to top
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Mon Sep 20, 2021 5:03 pm    Post subject: Reply with quote

See /etc/mpd.conf

That files is installed with the package. In that file you will find this ....

Code:
# General music daemon options ################################################
#
# This setting specifies the user that MPD will run as. MPD should never run as
# root and you may use this setting to make MPD change its user ID after
# initialization. This setting is disabled by default and MPD is run as the
# current user.
#
user                            "mpd"
#
# This setting specifies the group that MPD will run as. If not specified
# primary group of user specified with "user" setting will be used (if set).
# This is useful if MPD needs to be a member of group such as "audio" to
# have permission to use sound card.
#
#group                          "nogroup"


There are ways to have the start-stop daemon associated with "initsctipts" (OpenRc to be more precise) start a program as a user other than root. Sometimes the user or group parameter is passed from an /etc/conf.d/[servicename] file,sometimes the parmeter is written directly into the /etc/init.d/[servicename] file, and if I recall, there are also OpenRC variables. Ahh yes ...

/usr/share/doc/openrc-0.43.5/service-script-guide.md.bz2

Code:
If your daemon doesn't know how to change its own user or group, then
you can tell start-stop-daemon to launch it as an unprivileged user
with

  * command_user="user:group"


That variable might come into play if you are composing or editing a service start script, that is, a file in the /etc/init.d directory that will be used to start and stop a service.
Back to top
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 534
Location: France

PostPosted: Mon Sep 20, 2021 5:13 pm    Post subject: Reply with quote

fedeliallalinea wrote:
mpd openrc init script run as mpd user and audio group.


Hello.
This means that you probably do not have to do anything else but having service enabled/started (and having your regular account in audio group too, indeed) for your needs.
You sure need root privileges to start/stop, enable/disable services, but that does not mean the real service runs with root privileges...
If you got a little interest in code, just try and have a glance at file /etc/init.d/mpd (otherwise if file not present and using systemd, the output of
Code:
systemctl status mpd
will help you find out service file location): you might then get a better understanding.

++
Gi)
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Mon Sep 20, 2021 6:04 pm    Post subject: Reply with quote

sixtysixtysix wrote:
fedeliallalinea wrote:
mpd openrc init script run as mpd user and audio group.


while I realise that this is offered in a spirit of helpfulness, unfortunately it's exactly this kind of extreme brevity that has led to my current lack of understanding.

I simply don't understand what "init script run as mpd user" is supposed to mean! I get that one SHOULD NOT run mpd as root... so...
Normally when mpd is launched by OpenRC init scrpt, its priviliges are limited to mpd:audio. In other words, it is being automatically run as user "mpd" and group "audio".
If you see otherwise, then there's something wrong, unless you have explicitly changed some configs.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
sixtysixtysix
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jun 2021
Posts: 86

PostPosted: Tue Sep 21, 2021 12:02 pm    Post subject: Reply with quote

Thank you all for the further help and additional clarifications. I fear I may have muddied the waters slightly by being reasonably brief myself. I'm very happy to learn about this, so for further info/context:

In reading the Gentoo page on mpd I do NOT use a system-wide configuration, thus I referred mostly to this particular section:

https://wiki.gentoo.org/wiki/MPD#Per-user_configuration

I note, further to the helpful comments above, that it is possible/desirable to have mpd run at boot - I now understand (thank you) that by adding it to a run level (I hope that's the correct phrase?) I'm not actually running it as root.

The wiki says this regarding per-user config:

Quote:
Note
If your cron program supports @reboot you can create a cronjob that has /usr/bin/mpd start at boot in place of an init script.



I installed cronie (further to the general installation guide) so despite I haven't actually done anything with it, perhaps this is where I should be going? I'll read the manual to see if it supports @reboot. Of course, I can just use my DE settings to run an instance on login (as suggested above) - which I shall do for now, but again I'm happy to take the time to better understand this seemingly simply idea that comes wrapped in so much explanation :)
Back to top
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Tue Sep 21, 2021 1:46 pm    Post subject: Reply with quote

I just have mpd start as part of the normal machine starting sequence. It runs as user mpd and group audio, and that happened with zero effort on my part. It is the way the package installed. This command adds start of md to the machine startup sequence:

`rc-update add mpd default`

I typically brute force start and stop when there are issues, with direct command such as "/etc/init.d/mpd start" but there is a program part of openrc called "rc-service" that can also perform a service start without doing a reboot.

Not to say cronie isn't capable of the same thing. I limit cronie function to things to happen at set time of day - that's a personal choice, not a limitation of the cronie service. I also shun the "anacron" type function that cronie is capable of.

Edit to add: I just visited the wilki you cited. The "per user" section depends on the use of systemd for startup and services management. You are using openrc, not systemd. The two foundational system operation schemes are mutually exclusive. The "per user" instructions in the wiki don't apply to your current situation. The choice to use systemd can become a contentious subject. I'll say that I will refuse systemd for as long as I can. Openrc works for me, I understand it, and whatever the tradeoffs are between it and systemd don't give me any reason to switch. If I'd started on systemd and learned what's under THAT hood, I'd probably stay there.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum