Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Run service as user (equivelant of systemctl --user)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
hjkl
Apprentice
Apprentice


Joined: 22 Apr 2021
Posts: 198
Location: Somewhere in Europe

PostPosted: Mon Jun 21, 2021 3:27 pm    Post subject: Run service as user (equivelant of systemctl --user) Reply with quote

Hi,



I'd like to run a service as my own user instead of systemwide/root user.

Is there any way to do this with Openrc?

I haven't found any way to do so after a bit of research.

Cheers!
_________________
Having problems compiling since 2021 :(
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1530
Location: South America

PostPosted: Mon Jun 21, 2021 5:20 pm    Post subject: Reply with quote

systemctl --user sends commands to the per-user systemd process instead of the one that runs as process 1. The fact that services started that way result in corresponding processes running with a non-privileged effective user is just a side effect.

OpenRC doesn't have systemd-like per-user service managers. But you can have the 'system-wide' service manager spawn a process with a non-privileged user, though. start-stop-daemon and supervise-daemon have a --user option for doing that, and service scripts in /etc/init.d that implicitly call those programs (by not defining a start() function) can specify a value for that option by assigning to variable command_user:
Code:
command_user=user
or
Code:
command_user=user:group
Back to top
View user's profile Send private message
hjkl
Apprentice
Apprentice


Joined: 22 Apr 2021
Posts: 198
Location: Somewhere in Europe

PostPosted: Mon Jun 21, 2021 5:37 pm    Post subject: Reply with quote

GDH-gentoo wrote:
systemctl --user sends commands to the per-user systemd process instead of the one that runs as process 1. The fact that services started that way result in corresponding processes running with a non-privileged effective user is just a side effect.

OpenRC doesn't have systemd-like per-user service managers. But you can have the 'system-wide' service manager spawn a process with a non-privileged user, though. start-stop-daemon and supervise-daemon have a --user option for doing that, and service scripts in /etc/init.d that implicitly call those programs (by not defining a start() function) can specify a value for that option by assigning to variable command_user:
Code:
command_user=user
or
Code:
command_user=user:group



So I'd edit the /etc/init.d/<service> file and add that to the top of the file?
_________________
Having problems compiling since 2021 :(
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1530
Location: South America

PostPosted: Mon Jun 21, 2021 5:41 pm    Post subject: Reply with quote

fullbyte wrote:
So I'd edit the /etc/init.d/<service> file and add that to the top of the file?

What you do depends on the particular service script. Does it have a start() function? If no, does it have an assignment to variables command, command_args, command_background and/or supervisor?
Back to top
View user's profile Send private message
hjkl
Apprentice
Apprentice


Joined: 22 Apr 2021
Posts: 198
Location: Somewhere in Europe

PostPosted: Tue Jun 22, 2021 11:52 am    Post subject: Reply with quote

GDH-gentoo wrote:
fullbyte wrote:
So I'd edit the /etc/init.d/<service> file and add that to the top of the file?

What you do depends on the particular service script. Does it have a start() function? If no, does it have an assignment to variables command, command_args, command_background and/or supervisor?



Well, it's the MPD service:

Code:

#!/sbin/openrc-run
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

: CFGFILE=${CFGFILE:=/etc/mpd.conf}

depend() {
   need localmount
   use net netmount nfsmount alsasound esound pulseaudio
   config ${CFGFILE}
}

get_config() {
   x=$1
   test -e ${CFGFILE} || return 1
   sed -n \
     -e '/^[ \t]*'${x}'/{s:^[ \t]*'${x}'[ \t]\+"\?\([^#"]\+\)[^"]*"\?$:\1: ; p }' \
     ${CFGFILE}
}

extra_started_commands='reload'
# Required by io_uring
rc_ulimit="-l 65535"
command=/usr/bin/mpd
command_args=${CFGFILE}
required_files=${CFGFILE}
pidfile=$(get_config pid_file)
description="Music Player Daemon"

reload() {
      ebegin "Reloading ${RC_SVCNAME}"
      start-stop-daemon --pidfile ${pidfile} --signal HUP
      eend $?

  }

_________________
Having problems compiling since 2021 :(
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1530
Location: South America

PostPosted: Tue Jun 22, 2021 5:29 pm    Post subject: Reply with quote

Oh. But that is a package from Gentoo's repository, and I see that the configuration file that it installs as /etc/mpd.conf already tells mpd to drop privileges and run as user mpd. You are not supposed to change anything then, why do you want to?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo 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