I am running an Arch Linux installation and I have a systemd service that runs /etc/rc.local
. In rc.local
, I have several commands to perform things that I couldn't find a suitable solution for, like running dmesg -D
or something that would automatically create mount points in a temporary folder as in macOS with /Volumes
.
For each command in my rc.local
script, I have the script test for a failure and then exit with a number corresponding to the line of the command. So, a snippet of the file (adjusted to keep my formatting in mind) would look like this:
#!/bin/bash
dmesg -D || exit 1
i=2
for name in usb sd
do
mkdir -p /mnt/${name} || exit ${i}
i=$((i+1))
done
sysctl -w kernel.kptr_restrict=2 || exit 4
exit 0
This is a bit clunky and I'm under the impression that exit codes should be limited in their assignment for a script, but this is the only way I know how to check what the reason for my systemd service rc-local.service
failing is since systemctl status rc-local.service
will print out the exit value. Is there some other way to code rc.local
such that systemd/rc-local.service
will receive information on why rc.local
fails, like maybe passing a string to it or something? Then I can see this string show up maybe like this when I type systemctl status rc-local.service
:
Error reason: Failed to set kernel.kptr_restrict