How to make this command run as root automatically at bootup?

Should have been 2-6, I posted the wrong numbers above. Post is corrected.

I don’t have my wireless mouse connected right now, it’s currently on my laptop.

I’ve just tried it on Linux Mint (kernel 5.13) and it works here. My disable-usb.service looks like this:

[Unit]
Description=Disable-USB

[Service]
Type=oneshot
ExecStart=/usr/local/bin/disable-usb.sh

[Install]
WantedBy=multi-user.target

Notes:

  • It works with WantedBy=multi-user.target and WantedBy=default.target either way
  • It does not work with sh -c "echo 'disabled' > /sys/bus/usb/devices/2-6/power/wakeup" (despite journalctl reporting that the service has been started successfully, the usb port does not get disabled)

My disable-usb.sh looks like this:

#!/bin/bash

echo "disabled" > /sys/bus/usb/devices/2-6/power/wakeup

I will now reinstall Manjaro and try it with several kernels.

Okay, I’ve reinstalled Manjaro and tried it with the exact same .service and .sh file (ofc I did chmod with the appropriate permissions again) and it does not work. Neither with kernel 5.16, 5.15 or 5.10.

So, unfortunately, it seems to be a Manjaro/Arch issue :frowning:

I’VE GOT IT!! @xabbu was on the right trace after all! Big thanks to you!!

I gave up too early on my first attempt when I couldn’t make the process explicitly start after the last service (lightdm) with the After= option. But when I was going at it again, I found out that you can make the service “chill” and wait until the other bootup processes are finished by adding a Type=idle in the [Service] section of the service file (see man systemd.service).

So now my service file looks like this:

[Unit]
Description=Disable-USB

[Service]
Type=oneshot
ExecStart=/usr/local/bin/disable-usb.sh
Type=idle

[Install]
WantedBy=multi-user.target

Obviously Manjaro prioritizes startup processes and services differently than Mint. That’s why in Manjaro the USB bus’ folders are not already mounted when my service is run, which results in the “No such file or directory” error.


Random side note: This really seems to be a very nice community here, I must say! I’ve had two errors resolved within a couple of hours in this forum while in Mint and ubuntu forums, despite their large userbase, I’ve almost never found the help I needed. I’m really impressed and very grateful to all you people who tried to help me! :two_hearts:

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.