This article links to various methods to launch scripts or applications automatically when some particular event is taking place, like system startup or shutdown, shell login or logout and so on.
You can easily start your scripts or applications as daemons, see Daemon.
systemd is the default init framework, replacing initscripts. The services which are started by systemd can be found in the subfolders of
/etc/systemd/system/. Services can be enabled using the
systemctl command. For more information about systemd and how to write autostart scripts for it, see at systemd.
runit is a mature init system which offers process supervision, parallel startup, per-user service trees, granular cgroup manipulation, flexible dependency system, and boot times that don't incur the penalty of dbus. The root-level services are symlinks in
/service with the actual service directories in
/etc/sv. See the Runit page for more information.
To autostart programs in console or upon longin, you can use shell startup files/directories. Read the documentation for your shell, or its ArchWiki article, e.g. Bash or Zsh. Complete startup sequence for bash is explained in the "INVOCATION" section of "man 1 bash". When an interactive shell that is not a login shell is started, bash reads and executes commands from
/etc/profile is sourced by all Bourne-compatible shells upon login: it sets up an environment upon login and application-specific (
/etc/profile is executed, it sources
/etc/bash.bashrc if they are readable. After reading
/etc/profile, it looks for
~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. When a login shell exits, bash reads and executes commands from the files
/etc/bash.bash_logout, if the files exists.
If not running interactively, it just returns. Or
/usr/share/bash-completion/bash_completion is sourced.
~/.bashrc is sourced
STARTUP/SHUTDOWN FILESsection of
- Wikipedia:Unix_shell#Configuration files for shells
X session startup
X Desktop Group
$XDG_CONFIG_DIRS/autostart/: In this folder are
.desktop files. These files determine which programs are loaded for which desktop environment. For an explanation of the desktop file standard refer to Desktop Entry Specification.
GNOME, KDE, Xfce
You can also directly put .desktop files in
KDE also has a specific folder: