记一次在win2008下添加nginx自启动服务的操作

为了在win环境下添加nginx自启服务,我度娘了,

找到在cnblogs下(http://www.cnblogs.com/JayK/p/3429795.html)有篇文章是介绍如何添加nginx到win的自启动服务中。

步骤大概是下载个叫windows service Wrapper的程序-》配置该程序

 

下载地址我找了下,在http://www.veryhuo.com/down/html/82094.html有,原来blog的地址连接已经失效了。后续再挖掘,

发现有个新版https://github.com/kohsuke/winsw

另外这个网址http://www.cnblogs.com/tangruixin/p/3b6a686489f5445d8a5d4c6d1a3e6eb9.html也介绍了详细的配置方法。

 

按http://www.cnblogs.com/JayK/p/3429795.html来配置我的nginx自启动服务

2、把下载的文件(winsw-1.9-bin.exe)复制到nginx目录(D:\soft\nginx-1.10.2)

 

3、nginx目录下创建一个同名的Windows Service Wrapper的XML配置文件(winsw-1.9-bin.xml)

 

文件内容如下:

 

文件内容如下:

 

<?xml version="1.0" encoding="UTF-8" ?>

<service>

  <id>nginx</id>

  <name>nginx</name>

  <description>nginx</description>

  <executable>D:\soft\nginx-1.10.2\nginx.exe</executable>

  <logpath>D:\soft\nginx-1.10.2</logpath>

  <logmode>roll</logmode>

  <depend></depend>

  <startargument>-p D:\soft\nginx-1.10.2</startargument>

  <stopargument>-p D:\soft\nginx-1.10.2 -s stop</stopargument>

 

</service>

4、命令行执行安装命令

Windows Servcie Wrapper的命令格式如下:

 

# 安装服务

CMD:\> winsw-1.9-bin.exe install

 

# 卸载服务

CMD:\> winsw-1.9-bin.exe uninstall

 

# 启动服务

CMD:\> winsw-1.9-bin.exe start

 

# 停止服务

CMD:\> winsw-1.9-bin.exe stop

 

 

结语:后来研究了该服务的启动原理,从wrapper程序输出的日志中知道了参数的原理

 

2017-01-24 09:34:53 - Starting D:\soft\nginx-1.10.2\nginx.exe  

2017-01-24 09:34:53 - Started 660

2017-01-24 09:45:16 - Starting D:\soft\nginx-1.10.2\nginx.exe  

2017-01-24 09:45:16 - Started 3360

2017-01-24 09:48:41 - Starting D:\soft\nginx-1.10.2\nginx.exe  -p D:\soft\nginx-1.10.2

2017-01-24 09:48:41 - Started 3960

2017-01-24 09:48:47 - Stopping nginx

2017-01-24 09:48:47 - Started 2372

2017-01-24 09:48:47 - WaitForProcessToExit 3960+2372

2017-01-24 09:51:26 - Finished nginx

2017-01-24 09:53:13 - Starting D:\soft\nginx-1.10.2\nginx.exe  -p D:\soft\nginx-1.10.2

2017-01-24 09:53:13 - Started 3544

2017-01-24 09:53:34 - Stopping nginx

2017-01-24 09:53:35 - Started 1996

2017-01-24 09:53:35 - WaitForProcessToExit 3544+1996

2017-01-24 09:53:35 - Finished nginx

2017-01-24 09:55:27 - Starting D:\soft\nginx-1.10.2\nginx.exe  -p D:\soft\nginx-1.10.2

2017-01-24 09:55:27 - Started 1516

 

再反查nginx的启动参数“-p”,主要是指明nginx启动时的配置目录。我第一次配置时,没有把-p参数加在xml的“startargument”中,导致nginx启动时报错了,后来加上后,就解决了问题,从中又学到了知识。

 

另外查了下wrapper这个词典,是

 

 

我理解的在计算机的引申义是把所有的服务都“打包”好,

然后在http://zzk.cnblogs.com/s?t=b&w=Windows%20Service%20Wrapper

找到许多干货,原来java也需要进行“wrapper”打包的。

posted @ 2017-01-24 15:25  qkabcd  阅读(472)  评论(0编辑  收藏  举报