How to run a shell script at startup

前端 未结 21 2066
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:39

On an Amazon S3 Linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my

21条回答
  •  一向
    一向 (楼主)
    2020-11-22 14:13

    Working with Python 3 microservices or shell; using Ubuntu Server 18.04 (Bionic Beaver) or Ubuntu 19.10 (Eoan Ermine) or Ubuntu 18.10 (Cosmic Cuttlefish) I always do like these steps, and it worked always too:

    1. Creating a microservice called p example "brain_microservice1.service" in my case:

      $ nano /lib/systemd/system/brain_microservice1.service
      
    2. Inside this new service that you are in:

      [Unit]
      Description=brain_microservice_1
      After=multi-user.target
      
      [Service]
      Type=simple
      ExecStart=/usr/bin/python3.7 /root/scriptsPython/RUN_SERVICES/microservices    /microservice_1.py -k start -DFOREGROUND
      ExecStop=/usr/bin/python3.7 /root/scriptsPython/RUN_SERVICES/microservices/microservice_1.py -k graceful-stop
      ExecReload=/usr/bin/python3.7 /root/scriptsPython/RUN_SERVICES/microservices/microservice_1.py -k graceful
      PrivateTmp=true
      LimitNOFILE=infinity
      KillMode=mixed
      Restart=on-failure
      RestartSec=5s
      
      [Install]
      WantedBy=multi-user.target
      
    3. Give the permissions:

      $ chmod -X /lib/systemd/system/brain_microservice*
      $ chmod -R 775 /lib/systemd/system/brain_microservice*
      
    4. Give the execution permission then:

      $ systemctl daemon-reload
      
    5. Enable then, this will make then always start on startup

      $ systemctl enable brain_microservice1.service
      
    6. Then you can test it;

      $ sudo reboot now

    7. Finish = SUCCESS!!

    This can be done with the same body script to run shell, react ... database startup script ... any kind os code ... hope this help u...

    ...

提交回复
热议问题