linux设置nginx systemctl启动
生成nginx.pid文件
#验证nginx的配置,并生成nginx.pid文件
/usr/local/nginx/sbin/nginx -t
#pid文件目录在 /usr/local/nginx/run/nginx.pid
设置systemctl启动nginx
#添加之前需要先关闭启动状态的nginx,让nginx是未启动状态
#关闭nginx
/usr/local/nginx/sbin/nginx -s quit
#添加nginx.service文件
touch /lib/systemd/system/nginx.service
#向文件写入配置
tee /lib/systemd/system/nginx.service << EOF
[Unit] #对服务的说明
Description=nginx - high performance web server #描述服务
After=network.target remote-fs.target nss-lookup.target #描述服务类别
[Service] #服务的一些具体运行参数的设置
Type=forking #后台运行的形式
PIDFile=/usr/local/nginx/run/nginx.pid #PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload #重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop #停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit #快速停止
PrivateTmp=true #给服务分配临时空间
[Install]
WantedBy=multi-user.target #服务用户的模式
EOF
#在启动服务之前,需要先重载systemctl命令
systemctl systemctl daemon-reload
systemctl start nginx.service
systemctl status nginx
#添加之前需要先关闭启动状态的nginx,让nginx是未启动状态
#关闭nginx
/usr/local/nginx/sbin/nginx -s quit
#添加nginx.service文件
touch /lib/systemd/system/nginx.service
#向文件写入配置
tee /lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
#在启动服务之前,需要先重载systemctl命令
systemctl systemctl daemon-reload
systemctl start nginx.service
systemctl status nginx
linux设置tomcat systemctl启动
在/usr/local/tomcat/apache-tomcat-8.5.99/bin/catalina.sh设置tomcat.pid
vim catalina.sh
#########################################
CATALINA_PID="$CATALINA_BASH/tomcat.pid"
#######################################
启动tomcat生成pid文件
./bin/startup.sh
新建编辑tomcat 的systemctl执行文件
vim /etc/systemd/system/tomcat.service
Description=tomcat-console
[Unit]
Description=tomcat-console
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_112" #jdk的目录
PIDFile=/home/dangdang/soft/tomcat-console/tomcat.pid #tomcat路径
ExecStart=/home/dangdang/soft/tomcat-console/bin/startup.sh #tomcat下start.up路径
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#加载配置文件
systemctl daemon-reload
#tomcat systemctl命令
systemctl start tomcat-console #启动
systemctl stop tomcat-console #停止
systemctl restart tomcat-console #重启
systemctl enable tomcat-console #开机自启