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