Cannot start rc-local.service: Failed to connect to X Server

9,918

Thanks @bodhi.zazen for their kind instruction in the comments to my question!

To answer my question:

The problem is actually caused by the commands in rc.local, which contains the following line to enable natural scrolling:

/usr/bin/synclient VertTwoFingerScroll=1
/usr/bin/synclient HorizTwoFingerScroll=1
/usr/bin/synclient VertScrollDelta=-150
/usr/bin/synclient HorizScrollDelta=-150

However, executing this command requires connecting to the X Server, which all graphical applications depend on. However, rc.local is executed before X server is started, and thus the Failed to connect to X Server error.

To fix this, simply remove that line from rc.local, and sudo service rc.local start would work fine.

To answer my actual question:

Removing that line does not enable natural scrolling, though. In order to do this, you need to put the configuration in a Xorg configuration file.

Add the following lines to /usr/share/X11/xorg.conf.d/60-synaptics-options.conf, note that you don't have to chmod a+x.

# Synaptic options
Section "InputClass"
    Identifier "touchpad"
    Driver "synaptics"
    MatchIsTouchpad "on"
        # Enable natural scrolling
        Option "VertTwoFingerScroll" "1"
        Option "HorizTwoFingerScroll" "1"
        Option "VertScrollDelta" "-150"
        Option "HorizScrollDelta" "-150"
EndSection

reboot, and natural scrolling is enabled!

Share:
9,918

Related videos on Youtube

nalzok
Author by

nalzok

The best thing about being a statistician is that you get to play in everyone's backyard.

Updated on September 18, 2022

Comments

  • nalzok
    nalzok over 1 year

    Since I'm using 16.04, I have to manually start the rc.local service, so that commands in /etc/rc.local can be executed on start up. However, I'm having some trouble starting the service:

    sunqingyao@sunqingyao-MacBookAir:~$ sudo service rc.local start 
    Job for rc-local.service failed because the control process exited with error code. See "systemctl status rc-local.service" and "journalctl -xe" for details.
    

    Here is the output of systemctl status rc-local.service:

    sunqingyao@sunqingyao-MacBookAir:~$ systemctl status rc-local.service 
    ● rc-local.service - /etc/rc.local Compatibility
       Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
      Drop-In: /lib/systemd/system/rc-local.service.d
               └─debian.conf
       Active: failed (Result: exit-code) since Fri 2017-07-14 23:52:04 CST; 2min 13s ago
      Process: 2420 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)
    
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: Starting /etc/rc.local Compatibility...
    Jul 14 23:52:04 sunqingyao-MacBookAir rc.local[2420]: Failed to connect to X Server.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Control process exited, code=exited status=1
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: Failed to start /etc/rc.local Compatibility.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Unit entered failed state.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Failed with result 'exit-code'.
    

    and for journalctl -xe:

    Jul 14 23:52:04 sunqingyao-MacBookAir sudo[2390]: sunqingyao : TTY=pts/0 ; PWD=/home/sunqingyao ; USER=root ; COMMAND=/usr/sbin/service rc.local start
    Jul 14 23:52:04 sunqingyao-MacBookAir sudo[2390]: pam_unix(sudo:session): session opened for user root by (uid=0)
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: Starting /etc/rc.local Compatibility...
    -- Subject: Unit rc-local.service has begun start-up
    -- Defined-By: systemd
    -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- Unit rc-local.service has begun starting up.
    Jul 14 23:52:04 sunqingyao-MacBookAir rc.local[2420]: Failed to connect to X Server.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Control process exited, code=exited status=1
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: Failed to start /etc/rc.local Compatibility.
    -- Subject: Unit rc-local.service has failed
    -- Defined-By: systemd
    -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- Unit rc-local.service has failed.
    -- 
    -- The result is failed.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Unit entered failed state.
    Jul 14 23:52:04 sunqingyao-MacBookAir systemd[1]: rc-local.service: Failed with result 'exit-code'.
    Jul 14 23:52:04 sunqingyao-MacBookAir sudo[2390]: pam_unix(sudo:session): session closed for user root
    
    • derHugo
      derHugo almost 7 years
      Are you doing this local or over SSH?
    • Panther
      Panther almost 7 years
      Can you describe what you are trying to do ? "Failed to connect to X Server" suggests you are trying to run a graphical application and in that case you likely want to either find a command line solutions (as X is not running at boot or with init scripts) or run the command at login.
    • nalzok
      nalzok almost 7 years
      @derHugo I'm doing this on my local machine.
    • derHugo
      derHugo almost 7 years
      Did you try to run startx before?
    • nalzok
      nalzok almost 7 years
      @bodhi.zazen I'm trying to start the rc.local service on 16.04. Unfortunately, sudo systemctl enable rc-local.service executed without error, but the service isn't started. So I tried sudo service rc.local start.
    • Panther
      Panther almost 7 years
      You have to describe what you are doing with rc.local for us to debug it. In general using or calling graphical apps will fail if you are not logged in as X is not running. So yes it will run once you log in, but not at boot. So probably better to re-write your scripts to not use X or run it at log in and not boot.
    • nalzok
      nalzok almost 7 years
      @derHugo I just ran startx, and then my screen turned black so I had to force a reboot :(
    • nalzok
      nalzok almost 7 years
      @bodhi.zazen I have this in my rc.local: /usr/bin/synclient VertScrollDelta=-237, which is used to enable natural scrolling. I suppose it has something to do with "graphical apps"?
    • Panther
      Panther almost 7 years
      You should run that at login - askubuntu.com/questions/48321/… and not from rc.local, or you can write an xorg.conf
    • Panther
      Panther almost 7 years
    • nalzok
      nalzok almost 7 years
      @bodhi.zazen Ahh thanks, the service started successfully after I commented out that line! However, I want the natural scrolling command executed every time I wake up from hibernation (see my previous question), and waking up does not mean logging in, so your links probably won't do the job :(
    • Panther
      Panther almost 7 years
      Put your settings in /usr/share/X11/xorg.conf.d/60-synaptics-options.conf . See help.ubuntu.com/community/SynapticsTouchpad and wiki.archlinux.org/index.php/Touchpad_Synaptics
    • nalzok
      nalzok almost 7 years
      @bodhi.zazen After accidentally disabled my keyboard once, your method finally works! Please make these comments an answer, so that I can upvote and accept it!
    • Panther
      Panther almost 7 years
      Post your config as the solution
    • nalzok
      nalzok almost 7 years
      @bodhi.zazen I'm done!
    • iamanigeeit
      iamanigeeit about 4 years
      According to the /usr/share conf file, "DO NOT EDIT THIS FILE, your distribution will likely overwrite it when updating. Copy (and rename) this file into /etc/X11/xorg.conf.d first."