e2lc5's blog

e2lc5's blog

关于如何小区RecycleView自带的点击效果

((SimpleItemAnimator)rvLossInfo.getItemAnimator()).setSupportsChangeAnimations(false);

今天遇到一个之前遇到的问题

服务器返回包名中is_stock字段返回false,但检查服务器字段后发现其为tiny(1),当时解决了,今天又遇到一次,竟然忘了,附上解决方法

jdbc:mysql://{host}/{database}?tinyInt1isBit=false,添加tinyInt1isBit=false

SVN设置日志提交限制

服务器中安装的VisualSVN Server ,在新增Repositoreis时,每个Repositoreis(即新建的项目)下都会有一个hooks(钩子程序)在hooks目录下有一些tmpl文件,作为不同的hooks操作

新建一个pre-commit.bat文件,文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@echo off
setlocal
set SVN_BINDIR=C:/Program Files/VisualSVN Server/bin/
set REPOS=%1
set TXN=%2
rem check that logmessage contains at least 20 characters
svnlook log "%REPOS%" -t "%TXN%" | findstr "....." > nul
endlocal
if %errorlevel% gtr 0 goto err
exit 0
:err
echo 请填写Log!!!日志格式具体如下: 1>&2
echo 【提交类型】:BUG/新功能/需求修改/版本制作/代码整理/解决编译不过/阶段性递交/追加递交 1>&2
echo 【问题描述】:该单的描述,从devtrack中复制过来或从功能性对本次修改的描述 1>&2
echo 【程序描述】:无(原因分析或者是对修改的技术性描述) 1>&2
echo 【修改内容】: 1>&2
echo 1.修改的内容1 1>&2
echo 2.修改的内容1 1>&2
echo 【相关单号】:无 1>&2
echo 【需要测试】:是/否 1>&2
exit 1
通过TortoiseSVN设置,步奏如下(转):

1).在SVN所在的文件夹即项目(网络上是全体的,本地是只针对自己),右键TortoiseSVN,选择Properties(属性)

2).在弹出的界面中,选择new…(新建…),然后选择Other

3).在弹出的界面中,Property name项选择tsvn:logtemplate,然后在Property Value中填入模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
【提交类型】:BUG/新功能/需求修改/版本制作/代码整理/解决编译不过/阶段性递交/追加递交  

【问题描述】:该单的描述,从devtrack中复制过来或从功能性对本次修改的描述

【程序描述】:无(原因分析或者是对修改的技术性描述)

【修改内容】:

    1.修改的内容1

    2.修改的内容2

【相关单号】:无

【需要测试】:是/否

4).确定即可


作者:DracoTianlong
来源:CSDN
原文:https://blog.csdn.net/dracotianlong/article/details/41869857
版权声明:本文为博主原创文章,转载请附上博文链接!

Git常用命令

取消版本跟踪(文件或目录)
1
git rm –cached "文件或目录名"

有时会需要加f

1
git rm –cached -f "文件或目录名"

首先下载Tomcat8

建议安装lrzsz

root权限可直接使用apt install lrzsz

安装JDK(如有即跳过)

安装JDk 的时候,其实是很顺利的,只用了三个命令,就把他装好了,感觉也自动配好了环境变量,可以直接使用。
安装Ubuntu 16.04后要做的事 的第九条:安装Oracle Java
命令如下:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer(纯命令行还挺难装的)
sudo apt-get install openjdk-8-jdk
执行完上面三条命令以后,再执行下面三条命令,测试一下,安装是否成功
java -version
java
javac
至此,JDK安装完毕。

启动tomcat

进入tomcat_path/bin,执行sh startup.sh
启动后,如果你有公网ip,可能通过公网ip:8080无法访问,这个时候需要另一个神奇iptables
查看已启用的规则
iptables -L -n
开启80端口
iptables -A INPUT -p tcp -i eth0 –dport 80 -j ACCEPT
开启8080端口
iptables -A INPUT -p tcp -i eth0 –dport 8080 -j ACCEPT

允许loopback(不然会导致DNS无法正常关闭等问题)

IPTABLES -A INPUT -i lo -p all -j ACCEPT (如果是INPUT DROP)
IPTABLES -A OUTPUT -o lo -p all -j ACCEPT (如果是OUTPUT DROP)
保存iptables规则

iptables-save > /etc/iptables.up.rules
iptables规则自动保存与自动加载

nano /etc/network/interfaces
修改 /etc/network/interfaces ,添加下面末尾2行脚本

auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/network/iptables.up.rules
post-down iptables-save > /etc/network/iptables.up.rules

Tomcat Manager的用户配置是在Tomcat安装目录/conf/tomcat-users.xml文件中进行管理的。

Tomcat Manager的用户配置非常简单,下面我们以一个具体的配置为例:

如上所示,我们只需要在tomcat-users节点中配置相应的role(角色/权限)和user(用户)即可。一个user节点表示单个用户,属性username和password分别表示登录的用户名和密码,属性roles表示该用户所具备的权限。

user节点的roles属性值与role节点的rolename属性值相对应,表示当前用户具备该role节点所表示的角色权限。当然,一个用户可以具备多种权限,因此属性roles的值可以是多个rolename,多个rolename之间以英文逗号隔开即可。

稍加思考,我们就应该猜测到,rolename的属性值并不是随意的内容,否则Tomcat怎么能够知道我们随便定义的rolename表示什么样的权限呢。实际上,Tomcat已经为我们定义了4种不同的角色——也就是4个rolename,我们只需要使用Tomcat为我们定义的这几种角色就足够满足我们的工作需要了。

以下是Tomcat Manager 4种角色的大致介绍(下面URL中的*为通配符):

manager-gui:允许访问html接口(即URL路径为/manager/html/)
manager-script:允许访问纯文本接口(即URL路径为/manager/text/
)
manager-jmx:允许访问JMX代理接口(即URL路径为/manager/jmxproxy/)
manager-status:允许访问Tomcat只读状态页面(即URL路径为/manager/status/
)
2,地址绑定
修改apache-tomcat-8.5.5/webapps/manager/META-INF目录下的context.xml文件,注释这段代码。
修改apache-tomcat-8.5.5/webapps/host-manager/META-INF目录下的context.xml文件,注释这段代码。

1
2
3
4
5
6
<Context antiResourceLocking="false" privileged="true" >
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

安装

1
2
3
4
5
6
7
sudo apt-get update
sudo apt-get install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
sudo apt-get install -f

sudo netstat -tap | grep mysql

配置mysql

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
1、注释掉bind-address = 127.0.0.1:
mysql-uroot-p你的密码

1
2
3
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
flush privileges;
service mysql restart

服务管理

启动

sudo service mysql start

停止

sudo service mysql stop

服务状态

sudo service mysql status

在catalina.sh中加入这么一行:-Djava.security.egd=file:/dev/./urandom
或者
将$JAVA_HOME/jre/lib/security/java.security内的securerandom.source参数修改为file:/dev/./urandom
将securerandom.source参数修改为file:/dev/./urandom后,tomcat的问题解决。

或者在 /etc/systemd/system/tomcat.service JAVA_OPTS中添加
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

作者:qq_38293564
来源:CSDN
原文:https://blog.csdn.net/qq_38293564/article/details/80395389
版权声明:本文为博主原创文章,转载请附上博文链接!

3.1 在/etc/init.d目录下新建tomcat文件

sudo cd /etc/init.d
sudo vi tomcat
3.2 添加启动、关闭、重启的shell脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short Description: the tomcat Java Application Server
### END INIT INFO

RETVAL=0
export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export CATALINA_HOME=/home/xxx/apache-tomcat-9.0.11 # xxx为自己的用户名
export CATALINA_BASE=/home/xxx/apache-tomcat-9.0.11 # xxx为自己的用户名

start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ]
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo "OK"
return $RETVAL
fi
}


stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ]
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 3
ps -fwwu tomcat | grep apache-tomcat | grep -v grep | grep -v PID | awk '{print $2}'| xargs kill -9
echo "OK"
return $RETVAL
fi
}


case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restarting Tomcat"
$0 stop
sleep 3
$0 start
;;
*)
echo $"Usage:$0{start|stop|restart}"
exit 1
;;
esac

exit $RETVAL

3.3 保存退出,授予tomcat文件执行权限

chmod +x tomcat
3.4 使tomcat服务生效,并使能开机自启动,然后reboot重启,即可Tomcat开机自启动生效.
sudo systemctl daemon-reload #对于新创建的unit文件或修改了的unit文件,要通知systemd重载此配置文件;
sudo systemctl enable tomcat #使能开机自启动
sudo reboot
3.5 重启后,执行systemctl status tomcat看看tomcat服务的状态。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@localhost:~# systemctl status tomcat  
● tomcat.service
Loaded: loaded (/etc/init.d/tomcat; bad; vendor preset: enabled)
Active: active (running) since Thu 2018-08-23 21:54:25 PDT; 44s ago
Docs: man:systemd-sysv-generator(8)
Process: 811 ExecStart=/etc/init.d/tomcat start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/tomcat.service
└─832 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/home/localhost/apache-tomcat-9.0.11/conf/logging.propertie

Aug 23 21:54:24 localhost systemd[1]: Starting tomcat.service...
Aug 23 21:54:25 localhost tomcat[811]: $Starting Tomcat
Aug 23 21:54:25 localhost tomcat[811]: Tomcat started.
Aug 23 21:54:25 localhost tomcat[811]: OK
Aug 23 21:54:25 localhost systemd[1]: Started tomcat.service.

作者:相信美好的事情将会发生
来源:CSDN
原文:https://blog.csdn.net/bbaaEE/article/details/82015155
版权声明:本文为博主原创文章,转载请附上博文链接!

在Ubuntu下安装Nginx有以下方法,但是如果想要安装最新版本的就必须下载源码包编译安装。

基于APT源安装

sudo apt-get install nginx
安装好的文件位置:

/usr/sbin/nginx:主程序

/etc/nginx:存放配置文件

/usr/share/nginx:存放静态文件

/var/log/nginx:存放日志

其实从上面的根目录文件夹可以知道,Linux系统的配置文件一般放在/etc,日志一般放在/var/log,运行的程序一般放在/usr/sbin或者/usr/bin。

当然,如果要更清楚Nginx的配置项放在什么地方,可以打开/etc/nginx/nginx.conf

我猜测,Nginx如果指定默认加载/etc/nginx/nginx.conf的配置文件。如果要查看加载的是哪个配置文件,可以用这个命令sudo nginx -t或者ps -ef | grep nginx

然后通过这种方式安装的,会自动创建服务,会自动在/etc/init.d/nginx新建服务脚本,然后就可以使用sudo service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}的命令启动。

脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
. /etc/default/nginx
fi

STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

test -x $DAEMON || exit 0

. /lib/init/vars.sh
. /lib/lsb/init-functions

# Try to extract nginx pidfile
PID=$(cat /etc/nginx/nginx.conf | grep -Ev '^\s*#' | awk 'BEGIN { RS="[;{}]" } { if ($1 == "pid") print $2 }' | head -n1)
if [ -z "$PID" ]; then
PID=/run/nginx.pid
fi

if [ -n "$ULIMIT" ]; then
# Set ulimit if it is set in /etc/default/nginx
ulimit $ULIMIT
fi

start_nginx() {
# Start the daemon/service
#
# Returns:
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON -- \
$DAEMON_OPTS 2>/dev/null \
|| return 2
}

test_config() {
# Test the nginx configuration
$DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
}

stop_nginx() {
# Stops the daemon/service
#
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
RETVAL="$?"
sleep 1
return "$RETVAL"
}

reload_nginx() {
# Function that sends a SIGHUP to the daemon/service
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID --name $NAME
return 0
}

rotate_logs() {
# Rotate log files
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PID --name $NAME
return 0
}

upgrade_nginx() {
# Online upgrade nginx executable
# http://nginx.org/en/docs/control.html
#
# Return
# 0 if nginx has been successfully upgraded
# 1 if nginx is not running
# 2 if the pid files were not created on time
# 3 if the old master could not be killed
if start-stop-daemon --stop --signal USR2 --quiet --pidfile $PID --name $NAME; then
# Wait for both old and new master to write their pid file
while [ ! -s "${PID}.oldbin" ] || [ ! -s "${PID}" ]; do
cnt=`expr $cnt + 1`
if [ $cnt -gt 10 ]; then
return 2
fi
sleep 1
done
# Everything is ready, gracefully stop the old master
if start-stop-daemon --stop --signal QUIT --quiet --pidfile "${PID}.oldbin" --name $NAME; then
return 0
else
return 3
fi
else
return 1
fi
}

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start_nginx
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop_nginx
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"

# Check configuration before stopping nginx
if ! test_config; then
log_end_msg 1 # Configuration error
exit $?
fi

stop_nginx
case "$?" in
0|1)
start_nginx
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC configuration" "$NAME"

# Check configuration before stopping nginx
#
# This is not entirely correct since the on-disk nginx binary
# may differ from the in-memory one, but that's not common.
# We prefer to check the configuration and return an error
# to the administrator.
if ! test_config; then
log_end_msg 1 # Configuration error
exit $?
fi

reload_nginx
log_end_msg $?
;;
configtest|testconfig)
log_daemon_msg "Testing $DESC configuration"
test_config
log_end_msg $?
;;
status)
status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
;;
upgrade)
log_daemon_msg "Upgrading binary" "$NAME"
upgrade_nginx
log_end_msg $?
;;
rotate)
log_daemon_msg "Re-opening $DESC log files" "$NAME"
rotate_logs
log_end_msg $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2
exit 3
;;
esac

还有一个好处,创建好的文件由于放在/usr/sbin目录下,所以能直接在终端中使用nginx命令而无需指定路径。

通过源码包编译安装

这种方式可以自定安装指定的模块以及最新的版本。方式更灵活。

官方下载页面:http://nginx.org/en/download.html

configure配置文件详解:http://nginx.org/en/docs/configure.html

安装gcc g++的依赖库
1
2
sudo apt-get install build-essential
sudo apt-get install libtool
安装pcre依赖库(http://www.pcre.org/)
1
2
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
安装zlib依赖库(http://www.zlib.net)

sudo apt-get install zlib1g-dev

安装SSL依赖库(16.04默认已经安装了)

sudo apt-get install openssl
安装Nginx

下载最新版本:

wget http://nginx.org/download/nginx-1.14.2.tar.gz

解压:

tar -zxvf nginx-1.14.2.tar.gz

进入解压目录:

cd nginx-1.14.2

配置:

./configure --prefix=/usr/local/nginx

编译:

make

安装:

sudo make install

启动:

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过-h查看帮助命令。

查看进程:

ps -ef | grep nginx

配置软链接

sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
现在就可以不用路径直接输入nginx启动。

配置开机启动服务

在/etc/init.d/下创建nginx文件,sudo vim /etc/init.d/nginx,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
. /etc/default/nginx
fi

STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

test -x $DAEMON || exit 0

. /lib/init/vars.sh
. /lib/lsb/init-functions

# Try to extract nginx pidfile
PID=$(cat /usr/local/nginx/conf/nginx.conf | grep -Ev '^\s*#' | awk 'BEGIN { RS="[;{}]" } { if ($1 == "pid") print $2 }' | head -n1)
if [ -z "$PID" ]; then
PID=/run/nginx.pid
fi

if [ -n "$ULIMIT" ]; then
# Set ulimit if it is set in /etc/default/nginx
ulimit $ULIMIT
fi

start_nginx() {
# Start the daemon/service
#
# Returns:
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON -- \
$DAEMON_OPTS 2>/dev/null \
|| return 2
}

test_config() {
# Test the nginx configuration
$DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
}

stop_nginx() {
# Stops the daemon/service
#
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
RETVAL="$?"
sleep 1
return "$RETVAL"
}

reload_nginx() {
# Function that sends a SIGHUP to the daemon/service
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID --name $NAME
return 0
}

rotate_logs() {
# Rotate log files
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PID --name $NAME
return 0
}

upgrade_nginx() {
# Online upgrade nginx executable
# http://nginx.org/en/docs/control.html
#
# Return
# 0 if nginx has been successfully upgraded
# 1 if nginx is not running
# 2 if the pid files were not created on time
# 3 if the old master could not be killed
if start-stop-daemon --stop --signal USR2 --quiet --pidfile $PID --name $NAME; then
# Wait for both old and new master to write their pid file
while [ ! -s "${PID}.oldbin" ] || [ ! -s "${PID}" ]; do
cnt=`expr $cnt + 1`
if [ $cnt -gt 10 ]; then
return 2
fi
sleep 1
done
# Everything is ready, gracefully stop the old master
if start-stop-daemon --stop --signal QUIT --quiet --pidfile "${PID}.oldbin" --name $NAME; then
return 0
else
return 3
fi
else
return 1
fi
}

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start_nginx
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop_nginx
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"

# Check configuration before stopping nginx
if ! test_config; then
log_end_msg 1 # Configuration error
exit $?
fi

stop_nginx
case "$?" in
0|1)
start_nginx
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC configuration" "$NAME"

# Check configuration before stopping nginx
#
# This is not entirely correct since the on-disk nginx binary
# may differ from the in-memory one, but that's not common.
# We prefer to check the configuration and return an error
# to the administrator.
if ! test_config; then
log_end_msg 1 # Configuration error
exit $?
fi

reload_nginx
log_end_msg $?
;;
configtest|testconfig)
log_daemon_msg "Testing $DESC configuration"
test_config
log_end_msg $?
;;
status)
status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
;;
upgrade)
log_daemon_msg "Upgrading binary" "$NAME"
upgrade_nginx
log_end_msg $?
;;
rotate)
log_daemon_msg "Re-opening $DESC log files" "$NAME"
rotate_logs
log_end_msg $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2
exit 3
;;
esac
设置服务脚本有执行权限

sudo chmod +x /etc/init.d/nginx

注册服务
1
2
cd /etc/init.d/
sudo update-rc.d nginx defaults

现在基本上就可以开机启动了,常用的命令如下:
sudo service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}

参考:

http://www.cnblogs.com/piscesLoveCc/p/5794926.html(以上部分内容转自此篇文章)

http://www.linuxidc.com/Linux/2016-08/134080.htm

https://segmentfault.com/a/1190000002797601

原文

0%