pense-bête de bruno sanchiz

Accueil > Trucs Informatiques > Configurations > lancer un programme au démarrage

lancer un programme au démarrage

Publié le 11 décembre 2017, dernière mise-à-jour le 3 avril 2024, 2 visites, 23644 visites totales.

d’après https://www.baeldung.com/linux/run-script-on-startup :

cron

crontab -e @reboot sh /home/ec2-user/reboot_message.sh
Toutes les versions n’acceptent pas @reboot.

/etc/rc.local

#!/bin/bash
sh /home/bruno/br_/monte.sh
exit 0

chmod a+rwx /etc/rc.local && systemctl start rc-local.service && systemctl status rc-local.service

/etc/init.d/service_wrapper.sh

#! /bin/sh
case "$1" in
  start)
    # Executes our script
    sudo sh /home/ec2-user/reboot_message.sh
    ;;
  *)
    ;;
esac
exit 0

update-rc.d service_wrapper.sh defaults

systemd

/etc/systemd/system/reboot_message.service

[Unit]
Description=Reboot message systemd service.

[Service]
Type=simple
ExecStart=/bin/bash /home/ec2-user/reboot_message.sh

[Install]
WantedBy=multi-user.target

The file is organized into different sections :

Unit – contains general metadata, like a human-readable description
Service – describes the process and daemonizing behavior, along with the command to start the service
Install – enables the service to run at startup using the folder specified in WantedBy to handle dependencies
systemctl enable reboot_message.service


/etc/xdg/autostart

/etc/xdg/autostart/test.desktop

[Desktop Entry]
Type=Application
Exec=/home/linaro/autostart.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=MyScript
Comment=Runs MyScript script at system startup.

voir

  • centre de controle puis applications au démarrage ou directement : la commande est :
  • voir le répertoire /etc/xdg/autostart/ ,
  • voir /etc/init.d/ /etc/rc2.d ,/etc/init.d/README et man update-rc.d ; la commande est :

    où nom est le nom du programme placé en /etc/init.d/ et créé à partir du squelette /etc/init.d/skeleton

voir /etc/systemd/system

[bruno sanchiz]