0

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
nalzok
  • 257
  • 1
  • 4
  • 17
  • Are you doing this local or over SSH? – derHugo Jul 14 '17 at 16:07
  • 1
    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. – Panther Jul 14 '17 at 16:11
  • @derHugo I'm doing this on my local machine. – nalzok Jul 14 '17 at 16:16
  • Did you try to run startx before? – derHugo Jul 14 '17 at 16:18
  • @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. – nalzok Jul 14 '17 at 16:19
  • 1
    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. – Panther Jul 14 '17 at 16:20
  • @derHugo I just ran startx, and then my screen turned black so I had to force a reboot :( – nalzok Jul 14 '17 at 16:22
  • @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"? – nalzok Jul 14 '17 at 16:25
  • 1
    You should run that at login - https://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login and not from rc.local, or you can write an xorg.conf – Panther Jul 14 '17 at 16:31
  • See also https://askubuntu.com/questions/290009/how-do-i-make-my-synclient-settings-stick/362952 – Panther Jul 14 '17 at 16:32
  • @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 :( – nalzok Jul 14 '17 at 16:37
  • 2
    Put your settings in /usr/share/X11/xorg.conf.d/60-synaptics-options.conf . See https://help.ubuntu.com/community/SynapticsTouchpad and https://wiki.archlinux.org/index.php/Touchpad_Synaptics – Panther Jul 14 '17 at 16:49
  • @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! – nalzok Jul 14 '17 at 17:52
  • Post your config as the solution – Panther Jul 14 '17 at 17:58
  • @bodhi.zazen I'm done! – nalzok Jul 15 '17 at 01:25
  • 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." – iamanigeeit Feb 11 '20 at 02:19

1 Answers1

2

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!

nalzok
  • 257
  • 1
  • 4
  • 17