Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bat script automatically restarts Apache service under windows

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Problem description

The integrated environment phpstudy that the customer uses, which runs php+apahce+mysql, often causes the website to fail to open due to an unexplained apache exception, and the apache service needs to be restarted. Because it is not convenient to change the underlying environment, consider using bat scripts to automatically detect whether the website is working properly to determine whether the apache service needs to be restarted.

Preparation work 1, because with the help of the curl command to test whether the website is normal, it is necessary to install and configure the curl command in advance. Https://curl.haxx.se/download.html#Win64 download the corresponding version of the installation, and configure the environment variables. (you can use the curl command in cmd) 2. It is best to register apache as a system service, so that it is convenient to restart the service with net. Otherwise, you will have to specify a directory to restart. (registration system service is recommended to use nssm) Registration system service # if it is already a system service, you can skip this step, for example, you can register as a system service on phpstudy. Download, decompress and install the official website: http://nssm.cc/download selects 32-bit or 64-bit nssm according to the operating system, and starts the command line window in this directory It is recommended to write path environment variable 2, service registration (here is a screenshot of the previous registration of logstash) nssm install logstash will then pop up a box, select the start.bat to launch logstash at path and click Install service to fill in the corresponding path of the application and set Service name. Finally, click the install service button to perform the installation.

Script: Auto restart apache@echo offset url= http://www.*****.comecho% url%for / f% z in ('curl-so / dev/null-w% {http_code}% url%') do (set result=%%zecho% z) if% result% NEQ (:: echo% date%%time%% url% failed to open error code% result% > > C:\ log\% date:~0,4%%date:~5,2%% Date:~8,2%ERROR.lognet stop apache2anet start apache2a) else (:: echo% date%%time%% url% web page can open code% result% > > C:\ log\% date:~0,4%%date:~5,2%%date:~8,2%SUCCESS.logecho% date%%time%% url% web page can open code% result%) set task schedule to execute periodically

Customize the task schedule and repeat the detection

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report