简体   繁体   中英

Ubuntu EC2 - Run Python script on reboot

I have an Ubuntu 16.04 EC2 Instance and I need to run a python script every time the instance is Started. I tried everything suggested on every question in the forum and haven't had any luck yet.

Specifically I've tested:

  • Adding @reboot python3 /home/project/script.py to crontab
  • Adding @reboot /bin/startup.sh and having the bash file configured to run the /home/project/script.py
  • Using etc/rc.local , etc/init/mystartup.conf , etc/systemd/mystartup.conf
  • Passing User Data

Probably missing a few others and literally nothing worked even though running the script manually works wonders.

Thanks a lot in advance for the help!

Put the script into: /var/lib/cloud/scripts/per-boot/

Cloud-Init, which runs User Data, will also check this directory.

From Modules — cloud-init documentation :

Any scripts in the scripts/per-boot directory on the datasource will be run every time the system boots. Scripts will be run in alphabetical order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM