简体   繁体   中英

linux: determining if a running init.d script is executed as part of the system startup sequence

I am writing a init.d script that should run commands with certain options if it were being executed at system startup. The same script should run commands with other options if the user was manually executing the script.

For example, in a networking script, if it was being run at the system start up, then certain network interface would not be brought up depending on whether they should be configured ONBOOT. Otherwise, if the user was manually running the networking script (service network start), then all network interfaces would be brought up.

One way i can achieve this is to create a file say "/tmp/.boot" from the parent rc script, which is deleted after all startup scripts are executed. And then in the init script check of the existence of the file /tmp/.boot to determine if the script is being run as part of the startup sequence or not.

I was wondering if there is any existing way of knowing that the system is in its boot up sequence. Could something in /proc/ or elsewhere tell me that the system is in its boot sequence?

Looking forward to your suggestions.

Thanks and Regards ~Sameer

Firstly, the state in /proc should not be that much different for many scripts. The runlevel indicates whether you are in an early boot phase ( runlevel gives access to it), but at mid-boot the startup runlevel S is left.

However, this is not a bad thing and trying to write scripts that modify behaviour depending on the runlevel is evil. Undebugable. You might simply try other command line arguments instead, like 'start-all' instead of 'start'. Or you separate the RC script like Debian does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM