How to run a shell script at startup

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

    In Lubuntu I had to deal with the opposite situation. Skype start running after booting and I found in ~/.config/autostart/ the file skypeforlinux.desktop. The content of the file is as follows:

    [Desktop Entry]
    Name=Skype for Linux
    Comment=Skype Internet Telephony
    Exec=/usr/bin/skypeforlinux
    Icon=skypeforlinux
    Terminal=false
    Type=Application
    StartupNotify=false
    X-GNOME-Autostart-enabled=true
    

    Deleting this file helped me.

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

    Many answers on starting something at boot, but often you want to start it just a little later, because your script depends on e.g. networking. Use at to just add this delay, e.g.:

    at now + 1 min -f /path/yourscript
    

    You may add this in /etc/rc.local, but also in cron like:

    # crontab -e
    @reboot at now + 1 min -f /path/yourscript
    

    Isn't it fun to combine cron and at? Info is in the man page man at.

    As for the comments that @reboot may not be widely supported, just try it. I found out that /etc/rc.local has become obsolete on distros that support systemd, such as ubuntu and raspbian.

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

    You can do it :

    chmod +x PATH_TO_YOUR_SCRIPT/start_my_app 
    

    then use this command

    update-rc.d start_my_app defaults 100
    

    Please see this page on Cyberciti.

    0 讨论(0)
  • 2020-11-22 14:03
    • Add your script to /etc/init.d/ directory
    • Update your rc run-levels: $ update-rc.d myScript.sh defaults NN where NN is the order in which it should be executed. 99 for example will mean it would be run after 98 and before 100.
    0 讨论(0)
  • 2020-11-22 14:04

    Create your own /init executable

    This is not what you want, but it is fun!

    Just pick an arbitrary executable file, even a shell script, and boot the kernel with the command line parameter:

    init=/path/to/myinit
    

    Towards the end of boot, the Linux kernel runs the first userspace executable at the given path.

    Several projects provide popular init executables used by major distros, e.g. systemd, and in most distros init will fork a bunch of processes used in normal system operation.

    But we can hijack /init it to run our own minimal scripts to better understand our system.

    Here is a minimal reproducible setup: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/f96d4d55c9caa7c0862991025e1291c48c33e3d9/README.md#custom-init

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

    The absolute easiest method if all you want to run is a simple script, (or anything) is if you have a gui to use system > preferences then startup apps.

    just browse to the script you want and there you go. (make script executable)

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