rc.local 開啓自啓動,檢測是否成功

rc.localnginx

/etc/init.d/nginx start

查看運行狀態web

systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: failed (Result: exit-code) since 六 2018-07-07 09:40:03 CST; 5min ago
  Process: 1112 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)

7月 07 09:40:03 Ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
7月 07 09:40:03 Ubuntu rc.local[1112]: Starting nginx... nginx: [emerg] host not found in upstr
7月 07 09:40:03 Ubuntu rc.local[1112]:  failed
7月 07 09:40:03 Ubuntu systemd[1]: rc-local.service: Control process exited, code=exited status
7月 07 09:40:03 Ubuntu systemd[1]: Failed to start /etc/rc.local Compatibility.
7月 07 09:40:03 Ubuntu systemd[1]: rc-local.service: Unit entered failed state.
7月 07 09:40:03 Ubuntu systemd[1]: rc-local.service: Failed with result 'exit-code'.

發現是失敗的,緣由大概是沒有exit 0,再次嘗試重啓
rc.local調試

/etc/init.d/nginx start
exit 0

重啓rclocalrest

systemctl restart rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (running) since 六 2018-07-07 09:46:42 CST; 1min 49s ago
  Process: 3796 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
 Main PID: 3801 (nginx)
   CGroup: /system.slice/rc-local.service
           ├─3801 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/ng
           ├─3804 nginx: worker process                                          
           ├─3805 nginx: worker process                                          
           ├─3806 nginx: worker process                                          
           └─3807 nginx: worker process                                          

7月 07 09:46:42 Ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
7月 07 09:46:42 Ubuntu rc.local[3796]: Starting nginx...  done

再次查看狀態,發現成功了nginx。經過這兩條指令不須要每次都重啓電腦進行調試了,並且重啓電腦也不知道什麼緣由會啓動失敗。code

能夠經過這樣來檢測開機啓動是否能成功,而不是每次都要重啓,重啓!server

還能夠查看其餘服務的啓動狀況!generator

systemctl status nginx
● nginx.service - LSB: starts the nginx web server
   Loaded: loaded (/etc/init.d/nginx; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since 六 2018-07-07 10:13:22 CST; 3min 33s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 939 ExecStart=/etc/init.d/nginx start (code=exited, status=1/FAILURE)

7月 07 10:13:17 Ubuntu systemd[1]: Starting LSB: starts the nginx web server...
7月 07 10:13:22 Ubuntu nginx[939]: Starting nginx... nginx: [emerg] host not found in upstream 
7月 07 10:13:22 Ubuntu nginx[939]:  failed
7月 07 10:13:22 Ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1
7月 07 10:13:22 Ubuntu systemd[1]: Failed to start LSB: starts the nginx web server.
7月 07 10:13:22 Ubuntu systemd[1]: nginx.service: Unit entered failed state.
7月 07 10:13:22 Ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
相關文章
相關標籤/搜索