You are not logged in.

#1 2013-05-31 20:18:01

sobota
Member
Registered: 2012-04-05
Posts: 31

Systemd service and root script

I have simple "regroup.service" for systemd, it excue on start "script.sh". Systemd excue "regroup.service" on start but command in script requires root permission.

-rwxr--r-- 1 root root 316 05-31 21:24 /usr/lib/systemd/scripts/script.sh

Which way is the best for excue script via systemd?

Last edited by sobota (2013-05-31 20:19:11)

Offline

#2 2013-05-31 21:17:45

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,178

Re: Systemd service and root script

Does it not work? I'm assuming many scripts/commands at startup require root privileges. Could you explain what the problem is and what the script does?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2013-05-31 22:11:18

sobota
Member
Registered: 2012-04-05
Posts: 31

Re: Systemd service and root script

Script do:

#!/bin/sh

exist=false

start(){
fil=$(ls /dev/nvidia* | wc -l)

if [ $fil != "0" ]
then 
	exist=true
	chgrp video /dev/nvidia*
fi
}
stop(){

	if [ $exist ]
	then
		chgrp root /dev/nvidia*
	fi

}

case $1 in
	start|stop) "$1" ;;
	*) echo "You should pass correct options like start or stop" ;;
esac

When I call service "#systemctl start regroup" group is changed.

Last edited by sobota (2013-05-31 22:13:37)

Offline

#4 2013-05-31 22:18:43

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,178

Re: Systemd service and root script

I doubt this is the best way to do it but if that is what happens, what's the problem? Isn't that what the script is supposed to do?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2013-05-31 22:28:01

sobota
Member
Registered: 2012-04-05
Posts: 31

Re: Systemd service and root script

Problem is that after reebot with enable regroup.service group is default. It mean that script does't work.

Last edited by sobota (2013-05-31 22:31:17)

Offline

#6 2013-05-31 22:45:44

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,178

Re: Systemd service and root script

Have you looked into using a udev rule? I've never used them but it seems like just the sort of thing they are designed for.

EDIT: Also, are you sure you need to do this at all? I thought that most of the point of those groups vanished with the switch to systemd?

Last edited by cfr (2013-05-31 22:47:45)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB