How to run a shell script at startup

前端 未结 21 2151
伪装坚强ぢ
伪装坚强ぢ 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

    In the file you put in /etc/init.d/ you have to set it executable with:

    chmod +x /etc/init.d/start_my_app
    

    Thanks to @meetamit, if this does not run you have to create a symlink to /etc/rc.d/

    ln -s /etc/init.d/start_my_app /etc/rc.d/
    

    Please note that on latest Debian, this will not work as your script have to be LSB compliant (provide, at least, the following actions: start, stop, restart, force-reload, and status): https://wiki.debian.org/LSBInitScripts

    As a note, you should put the absolute path of your script instead of a relative one, it may solves unexpected issues:

    /var/myscripts/start_my_app
    

    And don't forget to add on top of that file:

    #!/bin/sh
    

提交回复
热议问题