*.rpm Fedora CentOS Redhat
at least in CentOS8, this file exists and is enabled per default (thanks!)
*.deb Debian Ubuntu Mint: disabled rc.local per default
why? oh why? here is how to re-enable it:
since debian 9.5 stretch the user will have to create it manually:
vim /etc/rc.local #!/bin/sh -e # # rc.local # # 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. # log time of startup/when rc.local was run echo "rc.local was run at startup on $(date '+%Y-%m-%d-%H:%M:%S')" >> /var/log/startup.log; exit 0
then go:
chmod +x /etc/rc.local;
systemctl daemon-reload;
systemctl start rc-local;
systemctl status rc-local;
status should look something like:
auto start graphical programs
is possible: username is the default-non-root desktop user, sleep 8 waits until desktop is ready, then a little “hack” is required to allow root to use the desktop (the programs are run as username)
sleep 8; export DISPLAY=':0.0' cp -v /home/username/.Xauthority /root/.Xauthority su username -c "/this/script.sh" & su username -c "/scripts/music.sh" &
the systemctrl service unit way: (more effort)
I saw this solution suggested which involves use of
systemd
here:
- Create a service:
sudo vi /etc/systemd/system/rc-local.service
- Add your code there:
[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
LXDE:
if you wanna autostart services that start before the desktop (non-grafical like mounting stuff) you can put them here:
Autostart files in an LXDE desktop and/or Openbox can be located in at least 5 places, depending upon the distro. These are
/etc/xdg/lxsession/LXDE/autostart /etc/xdg/openbox/autostart ~/.config/openbox/autostart.sh ~/.config/autostart /etc/xdg/autostart.
The first three are text files that are edited by adding text according to some format, and the last two are directories containing .desktop files for the processes that are to be started. If the lxde-core desktop is installed, then the lxde-autostart usually takes precedence in the command order. In an openbox-only distribution with no session-manager, generally ~/.config/autostart.sh rules. The two autostart files in the user’s home directory (~/) only apply to that user; the 3 in the etc directory apply to all users.
vim /etc/rc.local; # global-system-wide on every debian BEFORE DESKTOP
vim /etc/xdg/lxsession/LXDE/autostart; # for programs that start AFTER DESKTOP (LXDE) has started "autostart"
sudo vim ~/.config/lxsession/LXDE/autostart
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
@icedove
@lxterminal -e /scripts/SetScreen.sh
i don’t know which one worked… but it worked after:
echo "@lxterminal -e /scripts/welcome.sh" >> /etc/xdg/lxsession/LXDE/autostart; echo "@lxterminal -e /scripts/welcome.sh" >> /etc/xdg/openbox/autostart; echo "@lxterminal -e /scripts/welcome.sh" >> ~/.config/openbox/autostart.sh; echo "@lxterminal -e /scripts/welcome.sh" >> ~/.config/autostart; echo "@lxterminal -e /scripts/welcome.sh" >> /etc/xdg/autostart;
possible errors and solutions:
how to wait for a virtual machine to come online?
how to not exit the script if an command returns non-zero error code?
IP="192.168.122.100"
# if only LAN connection shall be used
/usr/sbin/rfkill block wifi
/usr/sbin/rfkill block bluetooth
# this strange || true is required
# or an error from virsh (non 0 exit code) will exit the entire script?
virsh shutdown fileshare || true
# to allow default eqmu user to access the vms that belong to user
echo "waiting for fileshare to shutdown..."
while ping -c 1 -W 1 $IP >/dev/null 2>&1; do
echo "waiting for $IP to shutdown..."
sleep 1 # Wait 1 second before retrying
done
umount /vms_bind_mount
bindfs /home/user/vms /vms_bind_mount/
chown -R libvirt-qemu:kvm /vms_bind_mount/
# to allow everyone to access the scripts belong to user (as only home dir is backedup)
# bindfs -u 1000 -g 1000 /home/user/scripts /scripts/
# su -c "/scripts/start.sh" user
virsh start fileshare
echo "waiting for fileshare to come online..."
while ! ping -c 1 -W 1 $IP >/dev/null 2>&1; do
echo "Waiting for $IP to come online..."
sleep 1 # Wait 1 second before retrying
done
echo "$IP is online!"
echo "fileshare is online, trying to mount..."
/home/user/scripts/mount_fileshare.sh
export DISPLAY=':0.0'
su user -c "/home/user/software/firefox/firefox-bin https://mas.to https://weather.com" &
exit 0
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!
