lnmp启动脚本


#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi

printf "=========================================================================\n"

printf "Manager for LNMP V0.8 , Written by Licess \n"
printf "=========================================================================\n"
printf "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux \n"
printf "This script is a tool to Manage status of lnmp \n"
printf "For more information please visit http://www.lnmp.org \n"
printf "\n"
printf "Usage: /root/lnmp {start|stop|reload|restart|kill|status}\n"
printf "=========================================================================\n"

NGINXNAME=nginx
NGINXCONFIGFILE=/usr/local/nginx/conf/$NGINXNAME.conf
NGINXPIDFILE=/usr/local/nginx/logs/$NGINXNAME.pid
NGINXDAEMON=/usr/local/nginx/sbin/$NGINXNAME
PHPFPMNAME=php-fpm
PHPFPMCONFIGFILE=/usr/local/php/etc/$PHPFPMNAME.conf
PHPFPMPIDFILE=/usr/local/php/logs/$PHPFPMNAME.pid
PHPFPMDAEMON=/usr/local/php/sbin/$PHPFPMNAME
HOSTNAME=`hostname`
MYSQLPIDFILE=/usr/local/mysql/var/$HOSTNAME.pid

function_start()
{
printf "Starting LNMP...\n"
if [ -f $NGINXPIDFILE ]; then
printf "Nginx is runing!\n"
exit 1
else
$NGINXDAEMON -c $NGINXCONFIGFILE
printf "Nginx start successfully!\n"
fi

if [ -f $PHPFPMPIDFILE ]; then
printf "php-fpm is runing!\n"
else
$PHPFPMDAEMON start
printf "PHP-FPM start successfully!\n"
fi

if [ -f $MYSQLPIDFILE ]; then
printf "MySQL is runing!\n"
else
/etc/init.d/mysql start
printf "MySQL start successfully!\n"
fi
}

function_stop()
{
printf "Stoping LNMP...\n"
if [ -f $NGINXPIDFILE ]; then
kill `cat $NGINXPIDFILE`
printf "Nginx program is stop\n"
else
printf "Nginx program is not runing!\n"
fi

if [ -f $PHPFPMPIDFILE ]; then
$PHPFPMDAEMON stop
printf "PHP-FPM program is stop\n"
else
printf "PHP-FPM program is not runing!\n"
fi

if [ -f $MYSQLPIDFILE ]; then
/etc/init.d/mysql stop
printf "MySQL program is stop\n"
else
printf "MySQL program is not runing!\n"
fi
}

function_reload()
{
printf "Reload LNMP...\n"
printf "Reload Nginx configure...\n"
$NGINXDAEMON -t
$NGINXDAEMON -s reload
printf "Nginx program is reloding!\n"
/etc/init.d/mysql reload
$PHPFPMDAEMON reload
}

function_restart()
{
printf "Reload LNMP...\n"
printf "Reload Nginx configure...\n"
$NGINXDAEMON -t
kill `cat $NGINXPIDFILE`
$NGINXDAEMON -c $NGINXCONFIGFILE
printf "Nginx program is restarting!\n"
/etc/init.d/mysql restart
$PHPFPMDAEMON restart
}

function_kill()
{
kill `cat $NGINXPIDFILE`
kill `cat $PHPFPMPIDFILE`
kill `cat $MYSQLPIDFILE`
}

function_status()
{
if [ -f $NGINXPIDFILE ]; then
printf "Nginx is runing!\n"
else
printf "Nginx is stop!\n"
fi

if [ -f $PHPFPMPIDFILE ]; then
printf "php-fpm is runing!\n"
else
printf "php-fpm is stop!\n"
fi
/etc/init.d/mysql status
}

case "$1" in
start)
function_start
;;
stop)
function_stop
;;
restart)
function_stop
function_start
;;
reload)
function_reload
;;
kill)
function_kill
;;
status)
function_status
;;
*)
printf "Usage: /root/lnmp {start|stop|reload|restart|kill|status}\n"
esac
exit

lnmp启动脚本

时间: 2024-10-05 16:57:49

lnmp启动脚本的相关文章

LNMP的Nginx启动脚本和配置文件

配置LNMP完成安装,并把PHP也解析完成,但是Nginx启动使用的是一个可执行文件:/usr/local/nginx/sbin/nginx 来启动,非常不方便,要给Nginx写一个启动脚本,同Apache,虽然Apache的启动脚本没有放到/etc/init.d目录下,但Apache有个非常方便的启动.重启.停止脚本,即:"apachectl",而Nginx没有这样的工具, 我们需要手动制作一个启动脚本,如下: [[email protected] ~]# vim /etc/init

LNMP环境下php-fpm启动脚本

安装LNMP环境,PHP5.4.37版本安装成功,添加php-fpm服务到系统启动项时,报错service php-fpm does not support chkconfig:php-fpm服务不支持chkconfig: 编辑/etc/init.d/php-fpm启动脚本,打开之后是乱码,查找原因是拷贝php-fpm启动脚本文件错误. 从同样环境下同样的php版本拷贝php-fpm启动脚本,重新编辑黏贴过来,保存退出后,可以正常加入启动项:有遇到同样情况的朋友可以直接复制脚本,保持与脚本内容的

LNMP搭建4:Nginx启动脚本和配置文件

Nginx没有像apachetl那样的启动脚本,我们需要手动做一个 [[email protected] html]# vim /etc/init.d/nginx 内容如下:http://www.apelearn.com/study_v2/chapter18.html #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # N

LNMP之 nginx 启动脚本和配置文件

因为 nginx 启动不方便,所以我们需要自已手动来编译一个nginx 的启动脚本 [[email protected] ~]# vim /etc/init.d/nginx  #加入以下内容 #!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx Settings NGINX_SBIN="/usr/local/nginx/s

lnmp安装脚本

lnmp安装脚本.一起学习.有更好的建议请留言. #!/bin/bash # # describe: linux nginx mysql php install FileS=/updatefile mkdir -p $FileS # 安装lrzsz 方便后续文件上传 wget http://vault.centos.org/6.5/os/x86_64/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm -P $FileS &>/dev/null rpm -v

ELK相关启动脚本

elasticsearch启动脚本 #!/bin/bash # Description:Elasticsearch ORS SERVER ES_HOME=/usr/local/elasticsearch-5.0.0 PID=$(jps | grep Elasticsearch | awk '{print $1}') ES_STOP=$ES_HOME/bin/shutdown.sh ES_START=$ES_HOME/bin/startup.sh #Necessary environment va

启动脚本_《UNIX/LINUX 系统管理技术手册 第四版》

1.init 是系统引导起来之后第一个运行的进程,是系统最重要的守护进程,进程号始终为1. 2.随着机器的引导,init从运行级0开始,一级一级往上运行到/etc/inittab中所设置的默认运行级.当机器关闭时,将以相反顺序执行同样的处理过程. 3.启动脚本的主要文件位于/etc/init.d这个目录下面,每个脚本负责一个守护进程或者系统的某个特定方面. 4.为了实现不同运行级别下需要运行那些脚本(并带什么参数,K开头停止.S开头启动),当系统进入到一个新的运行级别时,不是直接在init.d目

real server 的一个启动脚本例子

real server 的vip 启动脚本 #!/bin/bash #chkconfig: 2345 50 50 #description: real server init script VIP=192.168.80.80 case $1 in "start") echo "starting real server ..." ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up echo &quo

mongodb安装脚本/启动脚本/配置文件

安装脚本 #!/bin/bash  #author: QingFeng #qq: 530035210 #blog: http://my.oschina.net/pwd/blog  #自动安装mongodb和初始化配置 #缺省的配置如下   logdir=/data/log/shell          #日志路径 log=$logdir/shell.log            #日志文件  is_font=1                #终端是否打印日志: 1打印 0不打印  is_log