Rc.local doesn't seem to quite work

So I created this file /etc/rc.local and I made sure it has execute rights.

-rwxr-xr-x 1 root root 245 Nov 28 19:34 rc.local

So I have this script in it

imwheel
xcape -e 'Super_L=Alt_L|F1'

But for some reason it doesn’t launch if I start my PC up again, any idea why this is the case?

because you were using systemd?

After a quick read, I suppose systemd does not suport rc.local?

I suppose I should follow this then?

The proper way would be to set up a systemd service object for each command chunk in your rc.local file and not use rc.local at all as it’s a legacy method and should really only be used for compatibility.

For example, see this section in the imwheel wiki entry:

https://wiki.archlinux.org/title/IMWheel#Run_IMWheel_on_startup_using_a_service

You can also use /etc/profile.d/startup.sh but it’s less clean.

2 Likes

archwiki suggesting to run the systems service as user, what is almost the same as using profile way.
But systems service will work independent, so it will work in any case.

create the service file inside users path:
nano ~/.config/systemd/user/imwheel.service

enable service as user!
systemctl --user enable imwheel.service

1 Like

No - don’t use a deprecated approach. Instead, use the correct approach for the distro.

You’re trying to achieve an outcome from this, but instead of asking how best to do that you’re asking about something different. This is an XY Problem.

2 Likes

I have got so many different scripts I want to launch upon startup, is there a way I can do this instead of having to create each individual *.service, maybe perhaps I create a shell script and I create one *.service script and it points to the shell script to launch upon startup? Is that possible?

And if it is then is it possible for the shell script to launch in silence meaning that it doesn’t open up some terminal window?

Yeah sure I will use the appropriate solution.

Yes, you can create a service unit which calls a script. In your case, it should probably be a user service.

Can I some how elevate it in root privileges without being prompted for a password (because I have some code which requires root access)?

You shouldn’t elevate in a user service.

Can you tell us exactly what requires elevation? The most likely solution is to split it into 2 services. One with all the things that should be done as root and another with all the things that should be run as your user but without knowing the specifics it is hard to recommend the correct approach.

On Xfce: Settings → Session, Startup → Application Autostart. Add it there. You don’t need root privileges for this.

1 Like

How many really? And once you set it up, it’s done. Put the time in initially and then you’re good to go

#!/bin/bash

# Requires root permission
echo EHC1 > /proc/acpi/wakeup
echo EHC2 > /proc/acpi/wakeup
echo XHC > /proc/acpi/wakeup


imwheel

xcape -e 'Super_L=Alt_L|F1'

exit 0

So where I do some echo commands, is where I require root.

That makes more sense.

Even for the echo commands?

A few as you cann see mate :slight_smile:

This should probably be done in a normal service run as root, not a user service. It can also be rewritten as a single command, you don’t need a script for this.

This should be a separate service. There is a fully built service file here.

This should be an autostart script as @Kresimir suggested.

There are only 3 commands there…

what would I type for this service?

Oh ok thanks mate

Right I see mate.

Ok so in regards to imwheel

I created a file

~/.config/systemd/user/imwheel.service

And added the following in.

[Unit]
Description=IMWheel
Wants=display-manager.service
After=display-manager.service

[Service]
Type=simple
Environment=XAUTHORITY=%h/.Xauthority
ExecStart=/usr/bin/imwheel -d
ExecStop=/usr/bin/pkill imwheel
RemainAfterExit=yes

[Install]
WantedBy=graphical-session.target

I did run sudo systemctl enable imwheel but it can’t find the service

Failed to enable unit: Unit file imwheel.service does not exist.

It’s a user service so you need not starting it as root but as user:

systemctl --user enable imwheel

Thanks mate :slight_smile:

echo EHC1 > /proc/acpi/wakeup
echo EHC2 > /proc/acpi/wakeup
echo XHC > /proc/acpi/wakeup

In regards to this, how would I put this inside the systemD service? What would I type if you happened to know mate?