How to run a shell script at startup

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

    A simple approach is to add a line in /etc/rc.local :

    /PATH/TO/MY_APP &
    

    or if you want to run the command as a special user :

    su - USER_FOOBAR -c /PATH/TO/MY_APP &
    

    (the trailing ampersand backgrounds the process and allows the rc.local to continue executing)

    If you want a full init script, debian distro have a template file, so :

    cp /etc/init.d/skeleton /etc/init.d/your_app
    

    and adapt it a bit.

    0 讨论(0)
  • 2020-11-22 14:24

    I refered to this blog, always sound a good choice

    https://blog.xyzio.com/2016/06/14/setting-up-a-golang-website-to-autorun-on-ubuntu-using-systemd/

    vim /lib/systemd/system/gosite.service

    Description=A simple go website
    ConditionPathExists=/home/user/bin/gosite
    
    [Service]
    Restart=always
    RestartSec=3
    ExecStart=/home/user/bin/gosite
    
    [Install]
    WantedBy=multi-user.target
    
    
    systemctl enable gosite.service
    
    0 讨论(0)
  • 2020-11-22 14:26

    Painless, easiest and the most universal method is simply executing it with ~.bash_profile or ~.profile (if you don't have bash_profile file).

    Just add the execution command at the bottom of that file and it will be executed when system started.

    I have this one at the bottom an example; ~\Desktop\sound_fixer.sh

    0 讨论(0)
提交回复
热议问题