Skip to main content
Topic: convert/rewrite optimus-manager service for s6 (Read 370 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

convert/rewrite optimus-manager service for s6

Hi! I currently depend on optimus-manager for fast switching between intelgpu and nvidia graphics. however, the service for that is written for systemd. how would i go rewriting that service for s6? thx in advance!

Re: convert/rewrite optimus-manager service for s6

Reply #1
Hello. That's package is from AUR, I've checked the code a bit from github and it does not seems that has an hard dependency on systemd so you might have to write the script for s6. In this repo there are a lot of s6 scripts  and this website is the official documentation.
Artix Linux Colombia

Re: convert/rewrite optimus-manager service for s6

Reply #2
sorry for the late reply. only recently got free time to do this now, but i have some questions.
this is what the .service file looks like:
[Unit]
Description=Optimus Manager Commands Daemon
Before=display-manager.service

[Service]
ExecStartPre=-/usr/bin/python3 -u -m optimus_manager.hooks.pre_daemon_start
ExecStartPre=-/usr/bin/python3 -u -m optimus_manager.hooks.pre_xorg_start
ExecStart=/usr/bin/python3 -u -m optimus_manager.daemon
ExecStopPost=/usr/bin/python3 -u -m optimus_manager.hooks.post_daemon_stop

[Install]
WantedBy=graphical.target

i'm kinda confused about the "Before=display-manager.service" and the "ExecStartPre" arguments. how do i tell s6 to start "pre services" before the main service and how to i tell it to start these services before the display manager service?

Re: convert/rewrite optimus-manager service for s6

Reply #3
On how to do before you can sed this service to add to whichever displaymanager service’s dependencies file, you use. On the execpre you can just write the exec that needs to be ran before the main exec line.

Re: convert/rewrite optimus-manager service for s6

Reply #4
i'm a bit confused about the display manager part. is the display manager service the login manager (like lightdm or sddm) or is it some other service?

Re: convert/rewrite optimus-manager service for s6

Reply #5
i'm a bit confused about the display manager part. is the display manager service the login manager (like lightdm or sddm) or is it some other service?
Correct, like sddm, lightdm, etc

Re: convert/rewrite optimus-manager service for s6

Reply #6

i'm kinda confused about the "Before=display-manager.service" and the "ExecStartPre" arguments. how do i tell s6 to start "pre services" before the main service and how to i tell it to start these services before the display manager service?

Unfortunately, s6/s6-rc doesn't have a direct "Before=" equivalent. You can tell services to start after some other service though by using a dependencies file. See the s6-rc documentation.

Re: convert/rewrite optimus-manager service for s6

Reply #7
ok, so i'm done writing the service, but how do i add it to the s6 compiled database? the documentation doesnt seem to tell how

Re: convert/rewrite optimus-manager service for s6

Reply #8
btw, how do i attach a file here? i dont see an "attach file" button anywhere

Re: convert/rewrite optimus-manager service for s6

Reply #9
btw, how do i attach a file here? i dont see an "attach file" button anywhere
Therre is a "REPLY" button on the left right side.
Press it and you will be welcomed with new page in wwhich you can see the file dialog
"Add files by dragging & dropping or selecting them"
Man is as good as his tools.

Re: convert/rewrite optimus-manager service for s6

Reply #10
Best way is to write a pkgbuild to install it so it gets compiled and added to database.

Found the script that does the "compile". Make sure you add the service script inside a new dir in /etc/s6/sv and run
Code: [Select]
sh /usr/share/libalpm/scripts/s6-rc-db-update-hook

Re: convert/rewrite optimus-manager service for s6

Reply #11
here it is if anyone wants to test it :)
oh, and don't forget to add optimus-manager-daemon service as dependency of lightdm or sddm

Re: convert/rewrite optimus-manager service for s6

Reply #12
for some reason i'm getting this:

Code: [Select]
artix:[artix]:~$ optimus-manager --switch nvidia

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/dbus/bus.py", line 177, in activate_name_owner
    return self.get_name_owner(bus_name)
  File "/usr/lib/python3.8/site-packages/dbus/bus.py", line 361, in get_name_owner
    return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
  File "/usr/lib/python3.8/site-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.freedesktop.systemd1': no such name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/optimus-manager", line 33, in <module>
    sys.exit(load_entry_point('optimus-manager==1.3', 'console_scripts', 'optimus-manager')())
  File "/usr/lib/python3.8/site-packages/optimus_manager/client/__init__.py", line 55, in main
    _gpu_switch(config, args.switch, args.no_confirm)
  File "/usr/lib/python3.8/site-packages/optimus_manager/client/__init__.py", line 69, in _gpu_switch
    run_switch_checks(config, switch_mode)
  File "/usr/lib/python3.8/site-packages/optimus_manager/client/client_checks.py", line 10, in run_switch_checks
    _check_daemon_active()
  File "/usr/lib/python3.8/site-packages/optimus_manager/client/client_checks.py", line 25, in _check_daemon_active
    if not checks.is_daemon_active():
  File "/usr/lib/python3.8/site-packages/optimus_manager/checks.py", line 108, in is_daemon_active
    return _is_service_active("optimus-manager")
  File "/usr/lib/python3.8/site-packages/optimus_manager/checks.py", line 139, in _is_service_active
    return _is_service_active_dbus(system_bus, service_name)
  File "/usr/lib/python3.8/site-packages/optimus_manager/checks.py", line 143, in _is_service_active_dbus
    systemd = system_bus.get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
  File "/usr/lib/python3.8/site-packages/dbus/bus.py", line 241, in get_object
    return self.ProxyObjectClass(self, bus_name, object_path,
  File "/usr/lib/python3.8/site-packages/dbus/proxies.py", line 250, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
  File "/usr/lib/python3.8/site-packages/dbus/bus.py", line 182, in activate_name_owner
    self.start_service_by_name(bus_name)
  File "/usr/lib/python3.8/site-packages/dbus/bus.py", line 277, in start_service_by_name
    return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
  File "/usr/lib/python3.8/site-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.systemd1 was not provided by any .service files
artix:[artix]:~$

any ideas how i could fix it?

Re: convert/rewrite optimus-manager service for s6

Reply #13
You can try adding this patch during build of optimus-manager, not the s6 script : https://termbin.com/dq1x
 Though I don't know if it will work, but it's worth a try

Re: convert/rewrite optimus-manager service for s6

Reply #14
bit of a dumb question but how do i apply a patch? i'm not really experienced with git. sorry