You are not logged in.

#1 2012-10-26 08:54:07

yumtaoist
Member
Registered: 2011-10-09
Posts: 9

how to run a command automaticly on starting up with systemd

Hi,
I'm using a laptop with two video card, an ATI 3400 and a intel integrated video card.
Several months ago, I use rc.local to disable the ATI 3400 with the command below:

mount -t debugfs debugfs /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

What should I do to enable these commands with systemd?

Thank You!

Offline

#2 2012-10-26 08:56:59

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: how to run a command automaticly on starting up with systemd

Use tmpfiles. See man tmpfiles.d.

Offline

#3 2012-10-26 13:01:34

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,015

Re: how to run a command automaticly on starting up with systemd

Make a .service file and make sure that systemd calls it.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#4 2012-10-27 13:19:32

yumtaoist
Member
Registered: 2011-10-09
Posts: 9

Re: how to run a command automaticly on starting up with systemd

nomorewindows wrote:

Make a .service file and make sure that systemd calls it.

I have write a video.service file like below

[Unit]
Description=Disable the Discrete Graphics
Requires=sys-kernel-debug.mount
After=sys-kernel-debug.mount

[Service]
Type=oneshot
ExecStart=echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

And the result of "systemctl is-enabled video.service" is static

However, this just does not work. I'm not familiar with systemd.

Buy the way, thank you!

Offline

#5 2012-10-27 13:38:46

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: how to run a command automaticly on starting up with systemd

mount the debugfs via /etc/fstab and use tmpfiles.d to write OFF to /sys/kernel....

The service file does not work because ">" is a bash specific parameter and not interpreted by systemd. You would have to use something like "/bin/bash -c 'echo OFF > ...'". But nevertheless tmpfiles.d is the proper way to do this:
https://wiki.archlinux.org/index.php/Sy … rary_files

edit: also, you probably didn't even enable the service in the first place.
edit2: scratch the fstab idea, falconindy is right, debugfs is mounted by default, you don't have to worry about it.

Last edited by 65kid (2012-10-27 13:42:01)

Offline

#6 2012-10-27 13:40:17

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,097
Website

Re: how to run a command automaticly on starting up with systemd

debugfs is mounted for you. Tmpfiles is the way to do this.

Offline

#7 2012-10-27 20:08:43

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: how to run a command automaticly on starting up with systemd

yumtaoist wrote:
nomorewindows wrote:

Make a .service file and make sure that systemd calls it.

I have write a video.service file like below

[Unit]
Description=Disable the Discrete Graphics
Requires=sys-kernel-debug.mount
After=sys-kernel-debug.mount

[Service]
Type=oneshot
ExecStart=echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

And the result of "systemctl is-enabled video.service" is static

However, this just does not work. I'm not familiar with systemd.

Buy the way, thank you!

First of all, put this into /etc/systemd/system/. Then add an install section to this unit:

[Install]
WantedBy=multi-user.target

or

[Install]
WantedBy=basic.target

(No idea which one is better). Then run:

# systemctl daemon-reload
systemctl enable video.service

Offline

#8 2012-10-27 20:09:14

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: how to run a command automaticly on starting up with systemd

brain0 wrote:
yumtaoist wrote:
nomorewindows wrote:

Make a .service file and make sure that systemd calls it.

I have write a video.service file like below

[Unit]
Description=Disable the Discrete Graphics
Requires=sys-kernel-debug.mount
After=sys-kernel-debug.mount

[Service]
Type=oneshot
ExecStart=echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

And the result of "systemctl is-enabled video.service" is static

However, this just does not work. I'm not familiar with systemd.

Buy the way, thank you!

First of all, put this into /etc/systemd/system/. Then add an install section to this unit:

[Install]
WantedBy=multi-user.target

or

[Install]
WantedBy=basic.target

(No idea which one is better). Then run:

# systemctl daemon-reload
# systemctl enable video.service

Last edited by brain0 (2012-10-27 20:09:25)

Offline

#9 2012-11-01 15:37:52

holomorph
Member
Registered: 2012-10-19
Posts: 6

Re: how to run a command automaticly on starting up with systemd

In my system, the discrete gpu is card1, so I am able to use the udev rule

KERNEL=="card1", SUBSYSTEM=="drm", RUN+="/usr/bin/radeon"

where radeon is just a script:

#!/bin/sh
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

You should be able to find which device is your discrete card by trying

# udevadm info -a -p /sys/class/drm/cardX

Last edited by holomorph (2012-11-01 15:46:00)

Offline

#10 2012-11-10 16:45:21

yumtaoist
Member
Registered: 2011-10-09
Posts: 9

Re: how to run a command automaticly on starting up with systemd

Thank You, it works!

I create a file named "/etc/udev/rules.d/98-radeon.rules"

KERNEL=="card1", SUBSYSTEM=="drm", RUN+="/usr/bin/radeon"

and the "/usr/bin/radeon"

#!/bin/sh
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

then

chmod +x /usr/bin/radeon

Restart, then all works!
Thank you very much!

Please mark this as solved.


holomorph wrote:

In my system, the discrete gpu is card1, so I am able to use the udev rule

KERNEL=="card1", SUBSYSTEM=="drm", RUN+="/usr/bin/radeon"

where radeon is just a script:

#!/bin/sh
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

You should be able to find which device is your discrete card by trying

# udevadm info -a -p /sys/class/drm/cardX

Offline

#11 2012-11-10 16:58:48

adee
Member
From: The Moon
Registered: 2009-11-10
Posts: 107

Re: how to run a command automaticly on starting up with systemd

You're misusing udev for this. Use tmpfiles.d. It's a one-liner:

w /sys/kernel/debug/vgaswitcheroo/switch - - - - OFF

Last edited by adee (2012-11-10 17:00:25)

Offline

#12 2012-11-10 17:32:50

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: how to run a command automaticly on starting up with systemd

adee wrote:

You're misusing udev for this.

He is not.

Offline

#13 2012-11-11 02:44:29

yumtaoist
Member
Registered: 2011-10-09
Posts: 9

Re: how to run a command automaticly on starting up with systemd

I have try this, but it does not work, I think perhaps it is because that tmpfiles is excuted earlier than the mounting of debug module

adee wrote:

You're misusing udev for this. Use tmpfiles.d. It's a one-liner:

w /sys/kernel/debug/vgaswitcheroo/switch - - - - OFF

Offline

#14 2012-11-11 17:39:02

adee
Member
From: The Moon
Registered: 2009-11-10
Posts: 107

Re: how to run a command automaticly on starting up with systemd

yumtaoist wrote:

I have try this, but it does not work, I think perhaps it is because that tmpfiles is excuted earlier than the mounting of debug module

adee wrote:

You're misusing udev for this. Use tmpfiles.d. It's a one-liner:

w /sys/kernel/debug/vgaswitcheroo/switch - - - - OFF

Yup. I forgot to mention that I needed to put the intel and radeon modules in initramfs for this to work.

Last edited by adee (2012-11-11 17:39:33)

Offline

Board footer

Powered by FluxBB