System Boot Initialization
Systemd services handle boot and shutdown processes. Create service files in /etc/systemd/system/:
[Unit]
Description=Custom Startup Service
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/startup-script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Enable with: systemctl enable custom-service.service
User Session Initialization
User-level systemd services operate in ~/.config/systemd/user/:
[Unit]
Description=User Session Service
[Service]
Type=simple
ExecStart=/home/user/.local/bin/session-init
[Install]
WantedBy=default.target
Enable with: systemctl --user enable user-service.service
Shell Configuration Files
Bash executes scripts during shell initialization:
/etc/profile: System-wide login shell configuration~/.bash_profile: User-specific login shell configuration~/.bashrc: User-specific non-login shell configuration
Example .bashrc addition:
# Launch terminal multiplexer on shell start
if command -v tmux >/dev/null 2>&1 && [ -z "$TMUX" ]; then
exec tmux new-session -A -s main
fi
X11 Session Management
Xorg startup files execute before window manager initialization:
~/.xprofile: User-sepcific X session startup/etc/xprofile: System-wide X session startup
Example .xprofile:
# Set keyboard layout
setxkbmap -layout us -variant intl
# Configure display settings
xrandr --output HDMI-1 --auto --right-of eDP-1
Desktop Environment Autostart
XDG Autostart specification defines .desktop files in:
~/.config/autostart/: User-specific autostart entries/etc/xdg/autostart/: System-wide autostart entries
Example ~/.config/autostart/syncthing.desktop:
[Desktop Entry]
Type=Application
Name=Syncthing
Exec=syncthing -no-browser
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Window Manager Configuration
Window managers often include startup commands in configuration files:
i3 window manager (~/.config/i3/config):
# Launch applications on window manager start
exec --no-startup-id nm-applet
exec --no-startup-id blueman-applet
exec --no-startup-id feh --bg-scale ~/wallpaper.jpg
Event-Driven Automation
Udev Device Management
Create rules in /etc/udev/rules.d/ to trigger actions on device events:
# /etc/udev/rules.d/99-backup.rules
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/usr/local/bin/backup-trigger.sh"
Systemd Timers
Create timer units for scheduled execution:
/etc/systemd/system/daily-backup.timer:
[Unit]
Description=Daily Backup Timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
/etc/systemd/system/daily-backup.service:
[Unit]
Description=Daily Backup Service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup-system.sh
Filesystem Monitoring
Incron monitors filesystem events and executes commands:
Configure with incrontab -e:
/home/user/documents IN_CREATE,IN_MODIFY /usr/local/bin/process-document.sh
Inotify Event Monitoring
Use inotify-tools for filesystem event monitoring:
# Monitor directory for changes
inotifywait -m -r -e create,modify,delete /path/to/directory | while read event; do
echo "Filesystem event detected: $event"
/usr/local/bin/handle-change.sh
done