I have 2 graphics cards on my laptop. One is IGP and another discrete.
I've written a shell script to to turn off the discrete graphics card.
How can I convert it to systemd script to run it at start-up?
I have 2 graphics cards on my laptop. One is IGP and another discrete.
I've written a shell script to to turn off the discrete graphics card.
How can I convert it to systemd script to run it at start-up?
There are mainly two approaches to do that:
systemd service. Therefore you need two files: the script and the .service file (unit configuration file).
Make sure your script is executable and the first line (the shebang) is #!/bin/sh. Then create the .service file in /etc/systemd/system (a plain text file, let's call it vgaoff.service).
For example:
/usr/bin/vgaoff/etc/systemd/system/vgaoff.serviceNow, edit the unit file. Its content depends on how your script works:
If vgaoff just powers off the gpu, e.g.:
exec blah-blah pwrOFF etc
then the content of vgaoff.service should be:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/usr/bin/vgaoff
[Install]
WantedBy=multi-user.target
If vgaoff is used to power off the GPU and also to power it back on, e.g.:
start() {
exec blah-blah pwrOFF etc
}
stop() {
exec blah-blah pwrON etc
}
case $1 in
start|stop) "$1" ;;
esac
then the content of vgaoff.service should be:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/usr/bin/vgaoff start
ExecStop=/usr/bin/vgaoff stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
To power off:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo OFF > /whatever/vga_pwr_gadget/switch"
[Install]
WantedBy=multi-user.target
To power off and on:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo OFF > /whatever/vga_pwr_gadget/switch"
ExecStop=/bin/sh -c "echo ON > /whatever/vga_pwr_gadget/switch"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Once you're done with the files, enable the service:
systemctl enable vgaoff.service
It should start automatically after rebooting the machine.
For more details see systemd.service man page.
echo SOMETHING > /some/file does (or any other command as a matter of fact) should get familiar with the basics of CLI before attempting to run stuff on their systems. That aside, FYI, read how to switch dGPU off on several laptop models, see if the commands used there could be replaced with something like you suggest. Also, to restore the original file you usually reinstall the package that owns it.
– don_crissti
May 14 '13 at 23:56
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?