rc.local.service failed to start

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
benmoe

rc.local.service failed to start

Post by benmoe »

Hey,

I'm trying to start a script with the system. It is for the rotation of the screen of my HP Elitebook x360.
The Script itself works fine:

Code: Select all

#!/bin/sh
# Auto rotate touch screen based on device orientation.
#
#   Based on chadm's script at https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu.

# Receives input from monitor-sensor (part of iio-sensor-proxy package) and sets the touchscreen
# orientation based on the accellerometer positionn. We assume that the display rotation is 
# handled by Linux Mint 18.1, Cinnamon 3.2.7. If this is not the case, add the appropriate
# xrandr command into each case block.

# This script should be added to startup applications for the user.

# Kill any existing monitor-sensor instance, for example if manually invoking
# from a terminal for testing.
killall monitor-sensor

# Launch monitor-sensor and store the output in a RAM based file that can be checked by the rest of the script.
# We use the RAM based file system to save wear where an SSD is being used.
monitor-sensor > /dev/shm/sensor.log 2>&1 &

# Initialise display orientation to 'normal'
# Without this, the display often starts in 'inverted' (or 'bottom-up') mode!
xrandr --output eDP-1 --rotate normal
xinput set-prop 13 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1

# Parse output of monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify /dev/shm/sensor.log; do

# Read the last few lines that were added to the file and get the last orientation line.
ORIENTATION=$(tail /dev/shm/sensor.log | grep 'orientation' | tail -1 | grep -oE '[^ ]+$')

# Set the actions to be taken for each possible orientation
case "$ORIENTATION" in
bottom-up)
xrandr --output eDP-1 --rotate inverted 
xinput disable 14 && xinput set-prop 13 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;;
normal)
xrandr --output eDP-1 --rotate normal
xinput enable 14 && xinput set-prop 13 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1;;
right-up)
xrandr --output eDP-1 --rotate right
xinput disable 14 && xinput set-prop 13 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;;
left-up)
xrandr --output eDP-1 --rotate left
xinput disable 14 && xinput set-prop 13 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;;
esac
done
exit 0
I've created /etc/rc.local and added the script to this file.

Code: Select all

#!/bin/sh -e
#
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/etc/init.d/autorotate

exit 0
so far so good. But if I want to "systemctl start rc.local.service" it won't work.

systemctl status rc.local.service
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: activating (start) since Mon 2018-10-15 01:22:44 CEST; 45min ago
Docs: man:systemd-rc-local-generator(8)
Cntrl PID: 906 (rc.local)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/rc-local.service
├─ 906 /bin/sh -e /etc/rc.local start
├─ 909 /bin/sh /etc/init.d/autorotate
└─3694 inotifywait -e modify /dev/shm/sensor.log

rc.local[906]: /dev/shm/sensor.log MODIFY
rc.local[906]: Can't open display
rc.local[906]: Unable to connect to X server
rc.local[906]: Setting up watches.
rc.local[906]: Watches established.
rc.local[906]: /dev/shm/sensor.log MODIFY
rc.local[906]: Can't open display
rc.local[906]: Unable to connect to X server
rc.local[906]: Setting up watches.
rc.local[906]: Watches established.

I've not change anything in the rc.local.service file:

Code: Select all

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

This is one of the last "big" problems of Mint 19 on my HP Elitebook x360.
I hope you can help me out. Thank you in advanced.
Ben
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: rc.local.service failed to start

Post by thx-1138 »

benmoe

Re: rc.local.service failed to start

Post by benmoe »

Thank you! I've got it.

Now I try to disable the keyboard in every mode other then normal. When the Keyboard is disabled, florence should start as onscreen keyboard.
Florence dosen't start at this time and I don't know why.

best regards
Locked

Return to “Scripts & Bash”