Artix Linux Forum

Init systems => S6 => Topic started by: jroovy on 27 August 2020, 08:10:16

Title: convert/rewrite optimus-manager service for s6
Post by: jroovy on 27 August 2020, 08:10:16
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!
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jrballesteros05 on 27 August 2020, 12:40:51
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 (https://gitea.artixlinux.org/artixlinux/packages-s6) there are a lot of s6 scripts  and this website (https://skarnet.org/software/s6/servicedir.html) is the official documentation.
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 29 September 2020, 16:48:10
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?
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 29 September 2020, 18:39:08
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.
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 30 September 2020, 07:39:27
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?
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 30 September 2020, 10:39:19
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
Title: Re: convert/rewrite optimus-manager service for s6
Post by: Dudemanguy on 30 September 2020, 14:54:12

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 (https://skarnet.org/software/s6-rc/s6-rc-compile.html).
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 03 October 2020, 14:11:07
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
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 03 October 2020, 14:19:28
btw, how do i attach a file here? i dont see an "attach file" button anywhere
Title: Re: convert/rewrite optimus-manager service for s6
Post by: SGOrava on 03 October 2020, 15:58:14
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"
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 03 October 2020, 16:27:20
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
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 04 October 2020, 04:10:14
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
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 04 October 2020, 14:58:14
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?
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 04 October 2020, 15:36:26
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
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 04 October 2020, 18:48:17
bit of a dumb question but how do i apply a patch? i'm not really experienced with git. sorry
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 04 October 2020, 20:33:39
bit of a dumb question but how do i apply a patch? i'm not really experienced with git. sorry
Here I edited the pkgbuild and included the patch, all you got to do is extract it, and run makepkg -si
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 04 October 2020, 20:42:17
did you attached the file? i dont see a zip file
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 04 October 2020, 20:46:45
did you attached the file? i dont see a zip file
Sorry, thought I attached a link. http://www.filedropper.com/optimus-managertar
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 04 October 2020, 21:12:11
i think the archive's corrupt
sha1sum: 513f0107290867db06a563906f82b2678cf7420e  optimus-manager.tar.gz
Code: [Select]
# tar -xf optimus-manager.tar.gz 
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

could you upload it again?
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 04 October 2020, 21:23:23
i think the archive's corrupt
sha1sum: 513f0107290867db06a563906f82b2678cf7420e  optimus-manager.tar.gz
Code: [Select]
# tar -xf optimus-manager.tar.gz 
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

could you upload it again?
http://www.filedropper.com/optimus-manager
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 05 October 2020, 05:24:58
well, the systemd error is gone (thx for the patch!), but a new one came up:

Code: [Select]
artix:[artix]:~$ optimus-manager --status

Optimus Manager (Client) version 1.3

Current GPU mode : intel
GPU mode requested for next login : no change
GPU at startup : intel
Temporary config path: no
artix:[artix]:~$ optimus-manager --switch nvidia

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")
NameError: name '_is_service_active' is not defined
artix:[artix]:~$
Title: Re: convert/rewrite optimus-manager service for s6
Post by: SGOrava on 05 October 2020, 08:49:40
well, you should define some fake isserviceactive function or disable all code using it.
I would search for all uses of it and tried to remove it, since it is mess.
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 05 October 2020, 14:42:55
Try http://www.filedropper.com/optimus-manager_1
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 06 October 2020, 22:38:29
Did it work?
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 07 October 2020, 12:56:26
nope, still doesn't work
(sorry for late reply, was busy with other things)

Code: [Select]
artix:[artix]:~$ optimus-manager --status

Optimus Manager (Client) version 1.3

Current GPU mode : intel
GPU mode requested for next login : no change
GPU at startup : intel
Temporary config path: no
artix:[artix]:~$ optimus-manager --switch nvidia

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():
AttributeError: module 'optimus_manager.checks' has no attribute 'is_daemon_active'
artix:[artix]:~$
Title: Re: convert/rewrite optimus-manager service for s6
Post by: ndowens on 07 October 2020, 23:15:25
Here is another try http://www.filedropper.com/optimus-manager_2
If this doesn't work I am unsure what more can be done
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 08 October 2020, 06:40:26
nope, but we're getting closer. looks like the author put in a lot of checks
Code: [Select]
artix:[artix]:~$ optimus-manager --status

Optimus Manager (Client) version 1.3

Current GPU mode : intel
GPU mode requested for next login : no change
GPU at startup : intel
Temporary config path: no
artix:[artix]:~$ optimus-manager --switch nvidia

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 13, in run_switch_checks
    _check_patched_GDM()
  File "/usr/lib/python3.8/site-packages/optimus_manager/client/client_checks.py", line 54, in _check_patched_GDM
    dm_name = checks.get_current_display_manager()
AttributeError: module 'optimus_manager.checks' has no attribute 'get_current_display_manager'
artix:[artix]:~$
Title: Re: convert/rewrite optimus-manager service for s6
Post by: Dudemanguy on 08 October 2020, 14:52:47
I haven't looked very closely at this but the dbus 'org.freedesktop.systemd1' part actually should have worked if you have elogind running. elogind exposes this very same API and is able to receive that dbus message. Now this is done in python so I don't know if there's any limitation from python-dbus. I wouldn't think so but I've never looked at it in detail. It works in C however.
Title: Re: convert/rewrite optimus-manager service for s6
Post by: jroovy on 08 October 2020, 16:20:10
just checked. i already have elogind-log and elogind-srv running on startup. maybe something else is the problem? not so sure myself either
Title: Re: convert/rewrite optimus-manager service for s6
Post by: Dudemanguy on 08 October 2020, 17:05:15
I'm going to guess it's probably a python-dbus limitation then. At least with that particular function. Many programs send messages to "org.freedesktop.systemd1" which works without any problems with elogind. Of course, these programs use different dbus implementations (all in C) which is the major difference. I do not know what python-dbus does here exactly with that particular function call.
Title: Re: convert/rewrite optimus-manager service for s6
Post by: Hyperspace on 12 February 2021, 07:13:41
Just wondering, how's the progress of the Optimus Manager S6 rewrite?

I love using OM as it has the better performance/framerate compared to Bumblebee.