xml地图|网站地图|网站标签 [设为首页] [加入收藏]

常用服务自启动,停止脚本分享

来源:http://www.ccidsi.com 作者:集成经验 人气:105 发布时间:2019-07-24
摘要:服务器上的Nginx和PHP都以源码编写翻译安装的,不像ubuntu同样有自带service运行脚本,所以不帮忙类似从前的nginx(start|restart|stop|reload)了。自个儿出手太平盖世。以下脚本应有在奥德赛H

服务器上的Nginx和PHP都以源码编写翻译安装的,不像ubuntu同样有自带service运行脚本,所以不帮忙类似从前的nginx (start|restart|stop|reload)了。自个儿出手太平盖世。以下脚本应有在奥德赛HEL, Fedora, CentOS下都适用。

这边指的是编写翻译安装的软件 php redis nginx (mysql编写翻译安装的话默许自运转)

 独自等待

一、Nginx运转脚本/etc/init.d/nginx

php 开机运营 ,php安装的目录在 /usr/local/php

vim /etc/init.d/php-fpm  复制以下代码

#!/bin/sh

#

# php-fpm - this script starts and stops the php-fpm daemin

#

# chkconfig: - 85 15

# processname: php-fpm

# config: /usr/local/php/etc/php-fpm.conf

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="php-fpm daemon"

NAME=php-fpm

DAEMON=/usr/local/php/sbin/$NAME

CONFIGFILE=/usr/local/php/etc/php-fpm.conf

PIDFILE=/usr/local/php/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# If the daemon file is not found, terminate the script.

test -x $DAEMON || exit 0

d_start(){

$DAEMON -y $CONFIGFILE || echo -n " already running"

}

d_stop(){

kill -QUIT `/bin/cat $PIDFILE` || echo -n " no running"

}

d_reload(){

kill -HUP `cat $PIDFILE` || echo -n " could not reload"

}

case "$1" in

start)

echo -n "Starting $DESC: $NAME"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

d_stop

echo "."

;;

reload)

echo -n "Reloading $DESC configuration..."

d_reload

echo "Reloaded."

;;

restart)

echo -n "Restarting $DESC: $NAME"

d_stop

# Sleep for two seconds before starting again, this should give the nginx daemon some time to perform a graceful stop

sleep 2

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2

exit 3

;;

esac

exit 0

下面须求修改的 DAEMON /usr/local/php/sbin/$NAME  修改成为您php-fpm所在的目录

CONFIGFILE=/usr/local/php/etc/php-fpm.conf  你的php-fpm配置

PIDFILE=/usr/local/php/var/run/$NAME.pid  你的pid所在目录

这里值得注意的是,当您安装后从来运营你安装目录下sbin/php-fpm的时候并从未利用php-fpm.conf以及安装目录下的var/run的pid

进而在动用的时候记得去安插你的php-fpm.conf,开启pid所在的目录

接下来 chmod a x /etc/init.d/php-fpm //设置权限    chkconfig php-fpm on  //设置开机运行

1、编写脚本,名称为nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid

复制代码 代码如下:

Nginx  编写翻译安装在/usr/local/nginx 目录中

vim /etc/init.d/nginx  //以下代码是法定给的

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemon

#

# chkconfig:  - 85 15

# description:  NGINX is an HTTP(S) server, HTTP(S) reverse

#              proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /etc/nginx/nginx.conf

# config:      /etc/sysconfig/nginx

# pidfile:    /var/run/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {

# make required directories

user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`

if [ -z "`grep $user /etc/passwd`" ]; then

useradd -M -s /bin/nologin $user

fi

options=`$nginx -V 2>&1 | grep 'configure arguments:'`

for opt in $options; do

if [ `echo $opt | grep '.*-temp-path'` ]; then

value=`echo $opt | cut -d "=" -f 2`

if [ ! -d "$value" ]; then

# echo "creating" $value

mkdir -p $value && chown -R $user $value

fi

fi

done

}

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

make_dirs

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

sleep 1

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

怒供给修改的正是 

nginx="/usr/local/nginx/sbin/nginx"  // 你的nginx 运营目录

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"  //配置文件

chmod a x /etc/init.d/nginx            chkconfig nginx on

# Source function library.
. /etc/rc.d/init.d/functions

#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

redis 编写翻译安装在/usr/local/redis 目录中

# chkconfig:  2345 90 10

# description:  Redis is a persistent key-value database

PATH=/usr/local/redis

REDISPORT=6379

EXEC=/usr/local/redis/redis-server

REDIS_CLI=/usr/local/redis/redis-cli

#Redis密码

PASSWORD=

PIDFILE=/var/run/redis_6379.pid

CONF=/usr/local/redis/redis.conf

case "$1" in

start)

if [ -f $PIDFILE ]

then

echo "$PIDFILE exists, process is already running or crashed"

else

echo "Starting Redis server..."

$EXEC $CONF

fi

if [ "$?"="0" ]

then

echo "Redis is running..."

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo "$PIDFILE does not exist, process is not running"

else

PID=$(/bin/cat $PIDFILE)

echo "Stopping ..."

$REDIS_CLI -h localhost shutdown

while [ -x ${PIDFILE} ]

do

echo "Waiting for Redis to shutdown ..."

sleep 1

done

echo "Redis stopped"

fi

;;

restart|force-reload)

${0} stop

${0} start

;;

*)

echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2

exit 1

esac

PATH=/usr/local/redis

REDISPORT=6379

EXEC=/usr/local/redis/redis-server

REDIS_CLI=/usr/local/redis/redis-cli

#Redis密码

PASSWORD=

PIDFILE=/var/run/redis_6379.pid

CONF=/usr/local/redis/redis.conf

机动布置以上

chmod a x /etc/init.d/redis    chkconfig redis on

# Source networking configuration.
. /etc/sysconfig/network

编写好后保存,实践以下命令

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

复制代码 代码如下:

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

sudo chmod x /etc/init.d/nginx
sudo /sbin/chkconfig nginx on
# 检查一下
sudo /sbin/chkconfig --list nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

本文由68399皇家赌场发布于集成经验,转载请注明出处:常用服务自启动,停止脚本分享

关键词: 68399皇家赌场 Linux

最火资讯