You are not logged in.
I have a RX460 and I'm using the AMDGPU driver. I use GNOME3 as my DE.
I wrote a Python script which acts as a fancontrol for my RX460. I want it to be 0 RPM when I'm doing desktop work and the slowest possible speed for when I'm gaming. The script is pretty simple. It gets the GPUs temperature and then writes a "0" to /sys/class/drm/card0/device/hwmon/hwmon3/pwm1. (Or other values >0 depending on the temperature.)
Now when I start the script manually it works just fine. However when I make a systemd service for it and enable it, it doesn't do anything.
There's no error message and the journalctl logs don't show anything that looks suspicious.
Does anyone have any idea why this isn't working?
Is there a way to define the order of systemd services? I want my python script to be the very last service that gets started, so I can make sure amdgpu or any other driver/tool that might interfere with my script doesn't get in the way.
Thanks a lot in advance!!
Last edited by ArchArrow (2018-03-09 18:48:42)
Offline
Can you please post the script? And how you installed / enabled the service?
Offline
However when I make a systemd service for it and enable it, it doesn't do anything.
Did you also start the service, or did you reboot?
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Moving to Newbie Corner.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
man 7 systemd.special defines various targets used by systemd. For dependency handling see Systemd#Handling_dependencies as well as man 5 systemd.unit.
Offline
Yes, I can start the systemd service manually once I'm logged into Gnome3. And yes I enabled the service. Yet it still doesn't load. How can I make this service load as the very last service? Is there a way to specify this?
Another cause of error could be my service file:
[Unit]
Description=gpud service
[Service]
Type=idle
ExecStart=/usr/bin/python /home/user/gpud.py
[Install]
WantedBy=graphical-target.target
Offline
There's absolutely nothing in there about unit dependencies or timing. Read loqs link and at very least, add an After= field.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
I added "After=gdm.service" and "Wants=gdm.service" to the Unit section and rebooted, but nothing changed. It still doesn't start sucessfully. Yet it still works just fine if I start it manually.
Does anyone have any idea why this is?
Last edited by ArchArrow (2018-03-13 18:41:44)
Offline
Can you please post the script? And how you installed / enabled the service?
[Install]
WantedBy=graphical-target.target
graphical-target.target should be graphical.target. Please also post the status of the service and journalctl output for the service.
Offline
OK I changed it to graphical.target. Yet still no automatic startup. It still works just fine when starting it manually.
This is the journalctl output after a fresh reboot (before starting the service manually):
● gpud.service - gpud service
Loaded: loaded (/etc/systemd/system/gpud.service; enabled; vendor preset: disabled)
Active: inactive (dead)
This is my current service file:
[Unit]
Description=gpud service
After=gdm.service
Wants=gdm.service
[Service]
ExecStart=/usr/bin/python /home/user/gpud.py
[Install]
WantedBy=graphical.target
As previously stated, the script and service runs just fine when I start it manually. I tried making a *.desktop file so I can autostart it when logging into Gnome, but that asks me for my sudo password every single time after login, so it is less then ideal. I cannot imagine that this cannot be done with systemd. Does anyone have any idea how to solve this? My corrected service file should suffice, yet it still isn't starting the service. WHY?
Offline
This is the journalctl output after a fresh reboot (before starting the service manually):
● gpud.service - gpud service Loaded: loaded (/etc/systemd/system/gpud.service; enabled; vendor preset: disabled) Active: inactive (dead)
That is the output of systemctl status not the journal output for the unit gpud.service
What is the output of
ls /etc/systemd/system/graphical.target.wants/
systemctl status gdm.service
Offline
No problem, here are your infos:
sudo journalctl -u gpud
Mär 13 21:04:14 archlinux systemd[1]: Stopping gpud service...
Mär 13 21:04:14 archlinux systemd[1]: Stopped gpud service.
-- Reboot --
Mär 14 11:53:10 archlinux systemd[1]: Started gpud service.
Mär 14 13:45:50 archlinux systemd[1]: Stopping gpud service...
Mär 14 13:45:50 archlinux systemd[1]: Stopped gpud service.
-- Reboot --
Mär 15 00:58:38 archlinux systemd[1]: Started gpud service.
Mär 15 02:09:27 archlinux systemd[1]: Stopping gpud service...
Mär 15 02:09:27 archlinux systemd[1]: Stopped gpud service.
$ ls /etc/systemd/system/graphical-target.target.wants/
gpud.service
$ sudo systemctl status gpud
● gpud.service - gpud service
Loaded: loaded (/etc/systemd/system/gpud.service; enabled; vendor preset: disabled)
Active: inactive (dead)
$ sudo systemctl start gpud && sudo systemctl status gpud
● gpud.service - gpud service
Loaded: loaded (/etc/systemd/system/gpud.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-03-15 11:40:32 CET; 13ms ago
Main PID: 4064 (python)
Tasks: 1 (limit: 4915)
Memory: 2.8M
CGroup: /system.slice/gpud.service
└─4064 /usr/bin/python /home/user/gpud.py
Mär 15 11:40:32 archlinux systemd[1]: Started gpud service.
So it looks like it should work. Somehow the service still isn't started though. Why?
Update: I added this to the top of my script:
print("This script is running")
sys.stdout.flush()
so that I can see if it is actually running. (flush is needed to "force" the stdout to journalctl)
But when I look at the journalctl output "This script is running" does not show up. When I start it manually and then check the journalctl output, the "This script is running" appears. So this must mean that the script isn't even starting. I don't understand how this can be? Python should be available during boot, so the scrpit should run just fine. but it isn't executed it seems?!
Last edited by ArchArrow (2018-03-15 11:47:42)
Offline
systemctl status gdm.service
Also try adding debug to the boot options and see if there is any extra output related to gpud.
Offline
$ sudo systemctl status gdm
● gdm.service - GNOME Display Manager
Loaded: loaded (/usr/lib/systemd/system/gdm.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-03-20 11:55:00 CET; 53min ago
Main PID: 484 (gdm)
Tasks: 3 (limit: 4915)
Memory: 9.0M
CGroup: /system.slice/gdm.service
└─484 /usr/bin/gdm
Mär 20 11:55:00 archlinux systemd[1]: Starting GNOME Display Manager...
Mär 20 11:55:00 archlinux systemd[1]: Started GNOME Display Manager.
Mär 20 11:55:01 archlinux gdm[484]: GdmDisplay: display lasted 0.393944 seconds
Mär 20 11:55:01 archlinux gdm[484]: Child process -522 was already dead.
Mär 20 11:55:01 archlinux gdm[484]: Child process 505 was already dead.
Mär 20 11:55:01 archlinux gdm[484]: Unable to kill session worker process
Looks alright to me. It is so weird that it isn't working. There isn't even any sort of error message in dmesgn or journalctl.
I will have to try your tip with the debug boot options. Will report back
Offline
$ ls /etc/systemd/system/graphical-target.target.wants/
gpud.service
graphical-target.target should be graphical.target
Offline
graphical-target.target should be graphical.target
OK we're getting there. This did indeed help. (It was already correct in my gpud.service file but I had to disable and re-enable the service.
So, the script is now called correctly, but it doesn't have access to the files it needs.
This is the systemctl status output of my gpud service:
Mär 23 12:54:37 archlinux python[455]: This script is running
Mär 23 12:54:37 archlinux python[455]: Cannot read fan1_input
Mär 23 12:54:37 archlinux python[455]: Cannot read temp1_input
Mär 23 12:54:37 archlinux python[455]: Cannot read pwm1
And this is my Python script (with some extra debugging lines):
import sys
import time
print("This script is running")
sys.stdout.flush()
while True:
try:
f = open("/sys/class/drm/card0/device/hwmon/hwmon1/fan1_input", "r")
print("I CAN READ fan1_input")
sys.stdout.flush()
except:
print("Cannot read fan1_input")
sys.stdout.flush()
try:
t = open("/sys/class/drm/card0/device/hwmon/hwmon1/temp1_input", "r")
print("I CAN READ temp1_input")
sys.stdout.flush()
except:
print("Cannot read temp1_input")
sys.stdout.flush()
try:
p = open("/sys/class/drm/card0/device/hwmon/hwmon1/pwm1", "r+")
print("I CAN OPEN pwm1")
sys.stdout.flush()
except:
print("Cannot read pwm1")
sys.stdout.flush()
I also tried adding a PathExists line to the service file, but that doesn't seem to do anything.
[Unit]
Description=gpud service
After=gdm.service
Wants=gdm.service
[Service]
Type=simple
ExecStart=/usr/bin/python /home/user/gpud/gpud.py
[Path]
PathExists=/sys/class/drm/card0/device/hwmon/hwmon1/pwm1
[Install]
WantedBy=graphical.target
The code works perfectly fine when I start it manually while in Gnome. But for some reason when started as a systemd service the file(s) do(es)n't seem to exist yet.
Does anybody know why that is?
Last edited by ArchArrow (2018-03-23 12:05:42)
Offline
Checking that the path exists in the service file is the right way to go. But where did you get that syntax for doing so? There is no "PathExists" option, it's "ConditionPathExists" or "ConditionPathExistsGlob" and either of these must be in the "[Unit]" section, there is no "[Path]" section. Please read `man systemd.unit` and/or the wiki page on writing service files.
Last edited by Trilby (2018-03-23 12:11:30)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Checking that the path exists in the service file is the right way to go. But where did you get that syntax for doing so? There is no "PathExists" option, it's "ConditionPathExists" or "ConditionPathExistsGlob" and either of these must be in the "[Unit]" section, there is no "[Path]" section. Please read `man systemd.unit` and/or the wiki page on writing service files.
I read about it on a SO page. I changed it to "ConditionPathExists", but upon rebooting I get:
● gpud.service - gpud service
Loaded: loaded (/etc/systemd/system/gpud.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Condition: start condition failed at Fri 2018-03-23 13:47:43 CET; 18s ago
└─ ConditionPathExists=/sys/class/drm/card0/device/hwmon/hwmon1/pwm1 was not met
So it is still a timing issue.
When I boot the fans spin up pretty loudly and during boot (and before gdm) I can hear them be turned down (yet still not completely off). So that means that the driver was loaded and that the pwm1/fan1_input/etc files must exist in order for the driver to control the RPMs.
Yet why does it not work for my systemd file? It works perfectly fine in Gnome3 when I run it from a terminal.
Is there anyone with enough knowledge about the AMDGPU driver that can tell me more about the timing and what to do with the systemd service file?
Offline
Update:
I just fixed it. It seems like the timing that I need isn't possible with systemd, so I just added a
time.sleep(3)
to the top of my script and it now works as it should.
Thanks so much for all your help!
Offline
If you are going to take that approach, you'd be better off ditching all the Wants/After in the service file and just use a timer with OnBootSec
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline