[opensuse-factory] Start displaymanager only if monitor is connected
I have built a HTPC on Tumbleweed, that I use either for watching movies using Kodi or listen to music using mpd. I have enabled autologin so that the PC boots up without having to give the password. When I want to just listen to songs, I boot the PC without the monitor switched on. Next time I boot the PC with monitor switched on, the plasma desktop icon placement gets screwed up. The clock applet, the weather applet goes almost to the center instead of my preferred placement on the right side of the monitor. The only thing that works is to have autologin turned off in /etc/sysconfig/displaymanager. But this defeats the purpose of automatically logging in when the monitor is switched on. So I was thinking of a way the boot process can boot in runlevel 3 if monitor is not switched on. I found a way to detect this by installing the application monitor-get-edid. This program returns 0 if monitor is connected and switched on. It returns 1 if the monitor is not switched on. But I have not figured out a way to boot to graphical target automatically when monitor is switched on and boot to multi-user.target when monitor is switched off. So I have given up on the runlevel switching idea. Now I am thinking of another way to do it. Write a systemd service script that calls monitor-get-edid and runs the following script #!/bin/sh /usr/sbin/monitor-get-edid > /dev/null 2>&1 if [ $? -eq 0 ] ; then sed -i 's}.*DISPLAYMANAGER_AUTOLOGIN=.*}DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' /etc/sysconfig/displaymanager else # comment out DISPLAYMANAGER_AUTOLOGIN sed -i 's}.*DISPLAYMANAGER_AUTOLOGIN=.*}#DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' /etc/sysconfig/displaymanager fi Now how do I run this script before graphical.target ? Alternatively, is there a way that the graphical.target can wait forever wait till monitor-get-edid returns 0 -- Regards Manvendra - http://www.indimail.org GPG Pub Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC7CBC760014D250C -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Generally, I'd say it's a bug in KDE if widget placement gets messed up just because one forgets to switch on the screen.
[...] I have not figured out a way to boot to graphical target automatically when monitor is switched on and boot to multi-user.target when monitor is switched off.
Have you considered something like currernt_target=get_current_runlevel_target desired_target=get_desired_runlevel_target if [ "$current_target" = "$desired_target" ]; then echo "continuing boot..." else echo "wrong runlevel target; switching..." set_runlevel_target $desired_target shutdown -r now fi Joachim -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Mon, 3 Dec 2018 at 14:05, Joachim Wagner <jwagner@computing.dcu.ie> wrote:
Generally, I'd say it's a bug in KDE if widget placement gets messed up just because one forgets to switch on the screen.
Indeed this is a bug. If this bug wasn't there, I wouldn't have been trying out this complicated scheme.
[...] I have not figured out a way to boot to graphical target automatically when monitor is switched on and boot to multi-user.target when monitor is switched off.
Have you considered something like currernt_target=get_current_runlevel_target desired_target=get_desired_runlevel_target
if [ "$current_target" = "$desired_target" ]; then echo "continuing boot..." else echo "wrong runlevel target; switching..." set_runlevel_target $desired_target shutdown -r now fi
No. I did not consider this and this gives me a thought to try this out. Thank you for the idea. I could try the command "init 3" in place of "shutdown -r now" above. This is in case monitor-get-edid turns non-zero. Ultimately I want to do something where the graphical target waits till I switch on the monitor. So when I want the PC in headless mode, I don't switch on the monitor. In case I change my mind, all I need to do is switch on the monitor and the PC should boot into graphical mode (runlevel 5). So there are three scenarious 1. I power on the PC without the monitor switched on, the PC should boot into runlevel 3 2. I power on the PC with the monitor switched on, the PC should boot into runlevel 5 with autologin 3. I power on the PC without the monitor switched on, the PC should boot into runlevel 3. But any moment after the PC is booted, if I switch on the monitor, the PC should switch to runlevel 5 with autologin. I guess, I will have to deep dive into systemd scripts. At the moment I am going to try out this. monitor-check.service [Unit] Description=Monitor Check Service Before=display-manager.service [Service] ExecStart=/home/mbhanguin/bin/monitor_check Type=simple [Install] WantedBy=graphical.target The script /home/mbhangui/bin/monitor_check will be. Though I am not sure if this will work. #!/bin/sh file=/etc/sysconfig/displaymanager /usr/sbin/monitor-get-edid >/dev/null 2>&1 if [ $? -eq 0 ] ; then sed -i 's}#DISPLAYMANAGER_AUTOLOGIN=.*}DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' $file else sed -i 's}DISPLAYMANAGER_AUTOLOGIN=.*}#DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' $file fi -- Regards Manvendra - http://www.indimail.org GPG Pub Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC7CBC760014D250C -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Mon, 3 Dec 2018 at 13:23, Manvendra Bhangui <mbhangui@gmail.com> wrote:
So I was thinking of a way the boot process can boot in runlevel 3 if monitor is not switched on. I found a way to detect this by installing the application monitor-get-edid.
So finally I did it. With a bit of google search, I stumbled on this post which was about running a script when monitor gets connected. The command cat /sys/class/drm/card0-HDMI-A-1/status gives you the status of the connection of the monitor. https://superuser.com/questions/278082/linux-how-to-run-a-script-when-an-ext... So my final solution is a systemd service, a shell script and a udev rule 1) systemd service $ cat /usr/lib/systemd/system/monitor-check.service [Unit] Description=Monitor Hotplug Before=display-manager.service [Service] Type=simple RemainAfterExit=no ExecStart=/home/mbhangui/bin/monitor_plug.sh [Install] WantedBy=graphical.target 2) A shell script to put the system in runlevel 3 or runlevel 5 depending on if the monitor is connected $ cat monitor_plug.sh #!/bin/sh file=/etc/sysconfig/displaymanager uid=$(id -u mbhangui) #/usr/sbin/monitor-get-edid >/dev/null 2>&1 prev_state=$(cat /run/user/$uid/monitor_status 2>/dev/null) cur_state=$(cat /sys/class/drm/card0-HDMI-A-1/status 2>/dev/null) connect() { if [ "$cur_state" != "$prev_state" ] ; then sed -i 's}.*DISPLAYMANAGER_AUTOLOGIN=.*}DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' $file if [ ! -d /run/user/$uid ] ; then exit 0 fi echo $cur_state > /run/user/$uid/monitor_status systemctl is-active --quiet display-manager.service if [ $? -ne 0 ] ; then systemctl isolate graphical.target fi fi } disconnect() { if [ ! "$cur_state" = "$prev_state" ] ; then sed -i 's}.*DISPLAYMANAGER_AUTOLOGIN=.*}#DISPLAYMANAGER_AUTOLOGIN="mbhangui"}g' $file if [ ! -d /run/user/$uid ] ; then systemctl isolate multi-user.target exit 0 fi echo $cur_state > /run/user/$uid/monitor_status systemctl is-active --quiet display-manager.service if [ $? -eq 0 ] ; then systemctl isolate multi-user.target fi fi } if [ $(cat /sys/class/drm/card0-HDMI-A-1/status) == "connected" ] ; then connect elif [ $(cat /sys/class/drm/card0-HDMI-A-1/status) == "disconnected" ] ; then disconnect else exit 0 fi 3) udev rule in /etc/udev/rules.d/55-monitor.rules ACTION=="change" KERNEL=="card0", SUBSYSTEM=="drm", RUN+="/usr/bin/systemctl start monitor-check.service" -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
participants (2)
-
Joachim Wagner
-
Manvendra Bhangui