我试图找出为什么某个应用程序在我的 Raspberry Pi 上运行,结果发现有六种方法可以在启动时执行应用程序。这是我找到的。
- /etc/rc.local
- /home/pi/.bashrc
- 将脚本复制到 /etc/init.d/
- 系统控制
- 通过 crontab 进行安排
有没有办法从命令行识别启动时运行(或计划运行)的所有内容?
答案1
由于 debian 是一个基于 systemd 的发行版,因此您可以获得所有不错的工具!
因此,我不仅为您提供了系统处于“我已完成启动!”状态所需启动的所有事项的列表,而且还提供了一些其他工具的示例,您可以使用这些工具来获得更深入的了解上次启动期间发生的情况。
# Gives you a text-art tree of all the units that get started for
# your default boot target:
sudo systemctl list-dependencies default.target
# Takes the log from the last boot, and analyzes the critical chain, i.e.,
# what the things were the "next thing to happen" waited for the longest.
# For example, for a webserver to start, you might need to wait both for
# network to be up, as well as for the database server to be ready. The
# webserver might be the thing that the multiuser target was waiting for
# the longest, and not the synchronization of mails.
# This critical chain will show what was "blocking" the system from
# continuing to boot for the most part. It is a useful tool if you want to
# figure out how to optimize boot speed:
sudo systemd-analyze critical-chain
# Takes the log from the last boot, and list what took how long to
# start (and if it finishes, and isn't persistent, to finish), and
# outputs it as SVG data, which you can look at e.g. in your browser:
sudo systemd-analyze plot > boot-timings.svg
请注意,这仅包含“正常”系统启动内的内容。如果您有一个计时器(无论是通过 cron 还是其他方式),那么 systemd 就无法知道这一点。但这总是一样的——这总是一个很好的方式来忘记你做了一些滥用 cron 作为启动时启动的工具的事情,所以 Linux 发行版对于不允许软件包设置实际上并不存在的 cronjobs 非常严格。 cronjobs 但隐藏了启动时的启动程序。