How to run a shell script at startup

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

提交回复
热议问题