简体   繁体   中英

Why do we use"/etc/init.d/process start"

Why do we use /etc/init.d/httpd start in the below program? Why can't we use service httpd start ? For me it's showing as unrecognized service. (I have installed httpd already.)

#!/bin/bash
if (( $(ps -ef | grep httpd | wc -l) > 1 ))
then
   echo "httpd is running!!!"
else
   /etc/init.d/httpd start
fi

:-) vishal I don't mean to frustrate you. However, it's difficult to answer your question without a lot of assumptions.

Some considerations for not using /etc/init.d/httpd start

  • hard-coded location
  • assumes that httpd is stored in file /etc/init.d/httpd and not say apache2 or nginx or something else.
  • even the ps -ef test assumes the process name to be httpd and sometimes it's not

Some considerations for not using service httpd start

There may also be good reasons for not using service httpd start in this script because it may have side effects. For example,

  • service may not have httpd registered as a service
  • if you use service you may end up relaunching other dependent services which you may not want to do
  • service may bury the errors during start up and you may want to.

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