1.tengine的系統服務啓動腳本:
#!/bin/sh
[ $UID -ne 0 ] && {
echo "You must use the \"root\" user to operate."
exit 1
}
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0
nginxPrefix="/application/nginx"
tenginePrefix="/application/tengine"
if [ ! -d $nginxPrefix ];then
exit 1
else
[ -e $tenginePrefix ] || ln -s $nginxPrefix/ $tenginePrefix
[ -e $tenginePrefix/sbin/tengine ] || ln -s $tenginePrefix/sbin/nginx $tenginePrefix/sbin/tengine
[ -e $tenginePrefix/conf/tengine.conf ] || ln -s $tenginePrefix/conf/nginx.conf $tenginePrefix/conf/tengine.conf
fi
tengine="$tenginePrefix/sbin/tengine"
prog=$(basename $tengine)
sysconfig="/etc/sysconfig/$prog"
lockfile="$tenginePrefix/logs/tengine"
pidfile="$tenginePrefix/logs/${prog}.pid"
TENGINE_CONF_FILE="$tenginePrefix/conf/tengine.conf"
if [ ! -f $sysconfig ];then
cat >$sysconfig<<EOF
# Configuration file for the tengine service
# set this to the location of the tengine configuration file
TENGINE_CONF_FILE=$tenginePrefix/conf/tengine.conf
EOF
fi
grep "${prog}.pid" $tenginePrefix/conf/nginx.conf &>>/dev/null
if [ $? -ne 0 ];then
sed -i '9a pid logs\/tengine.pid;' $tenginePrefix/conf/nginx.conf
fi
[ -f $sysconfig ] && . $sysconfig
start() {
[ -x $tengine ] || exit 5
[ -f $TENGINE_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $tengine -c $TENGINE_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest_q || return 6
stop
start
}
reload() {
configtest_q || return 6
echo -n $"Reloading $prog: "
killproc -p $pidfile $prog -HUP
echo
}
configtest() {
$tengine -t -c $TENGINE_CONF_FILE
}
configtest_q() {
$tengine -t -q -c $TENGINE_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
upgrade() {
local oldbin_pidfile="${pidfile}.oldbin"
configtest_q || return 6
echo -n $"Upgrading $prog: "
killproc -p $pidfile $prog -USR2
retval=$?
sleep 1
if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then
killproc -p $oldbin_pidfile $prog -QUIT
success $"$prog online upgrade"
echo
return 0
else
failure $"$prog online upgrade"
echo
return 1
fi
}
reopen_logs() {
configtest_q || return 6
echo -n $"Reopening $prog logs: "
killproc -p $pidfile $prog -USR1
retval=$?
echo
return $retval
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest|reopen_logs)
$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
exit 2
esac
2.執行效果:
[root@linux ~]
total 4.0K
drwxr-xr-x 10 root root 4.0K Aug 4 12:34 nginx
lrwxrwxrwx 1 root root 19 Aug 4 17:16 tengine -> /application/nginx/
[root@linux ~]
total 32K
drwxr-xr-x 2 root root 4.0K Aug 4 12:31 html
drwxr-xr-x 2 root root 4.0K Aug 4 12:31 modules
drwxr-xr-x 2 root root 4.0K Aug 4 12:31 include
drwx------ 2 tengine root 4.0K Aug 4 12:34 proxy_temp
drwx------ 2 tengine root 4.0K Aug 4 12:34 client_body_temp
drwxr-xr-x 2 root root 4.0K Aug 4 17:16 sbin
drwxr-xr-x 2 root root 4.0K Aug 4 17:16 conf
drwxr-xr-x 2 root root 4.0K Aug 5 08:48 logs
[root@linux ~]
total 72K
-rw-r--r-- 1 root root 2.2K Aug 4 12:31 koi-win
-rw-r--r-- 1 root root 2.8K Aug 4 12:31 koi-utf
-rw-r--r-- 1 root root 3.6K Aug 4 12:31 win-utf
-rw-r--r-- 1 root root 4.0K Aug 4 12:31 mime.types
-rw-r--r-- 1 root root 4.0K Aug 4 12:31 mime.types.default
-rw-r--r-- 1 root root 964 Aug 4 12:31 fastcgi_params
-rw-r--r-- 1 root root 964 Aug 4 12:31 fastcgi_params.default
-rw-r--r-- 1 root root 1.1K Aug 4 12:31 fastcgi.conf
-rw-r--r-- 1 root root 1.1K Aug 4 12:31 fastcgi.conf.default
-rw-r--r-- 1 root root 623 Aug 4 12:31 uwsgi_params
-rw-r--r-- 1 root root 623 Aug 4 12:31 uwsgi_params.default
-rw-r--r-- 1 root root 596 Aug 4 12:31 scgi_params
-rw-r--r-- 1 root root 596 Aug 4 12:31 scgi_params.default
-rw-r--r-- 1 root root 2.8K Aug 4 12:31 nginx.conf.default
-rw-r--r-- 1 root root 5.1K Aug 4 12:31 browsers
-rw-r--r-- 1 root root 3.3K Aug 4 12:31 module_stubs
lrwxrwxrwx 1 root root 36 Aug 4 17:16 tengine.conf -> /application/tengine/conf/nginx.conf
-rw-r--r-- 1 root root 2.8K Aug 4 17:16 nginx.conf
[root@linux ~]
total 4.6M
-rwxr-xr-x 1 root root 4.6M Aug 4 12:31 nginx
-rwxr-xr-x 1 root root 19K Aug 4 12:31 dso_tool
lrwxrwxrwx 1 root root 31 Aug 4 17:16 tengine -> /application/tengine/sbin/nginx
[root@linux ~]
total 16K
-rw-r--r-- 1 root root 833 Aug 4 12:56 error.log
-rw-r--r-- 1 root root 4.3K Aug 4 19:54 access.log
-rw-r--r-- 1 root root 5 Aug 5 08:48 tengine.pid
-rw-r--r-- 1 root root 0 Aug 5 08:48 tengine
[root@linux ~]
[root@linux ~]
Usage: /etc/init.d/tengine {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}
[root@linux ~]
tengine is stopped
[root@linux ~]
Starting tengine: [ OK ]
[root@linux ~]
tengine (pid 1672 1670) is running...
[root@linux ~]
root 1670 1 0 08:46 ? 00:00:00 nginx: master process /application/tengine/sbin/tengine -c /application/tengine/conf/tengine.conf
tengine 1672 1670 0 08:46 ? 00:00:00 nginx: worker process
[root@linux ~]
Stopping tengine: [ OK ]
[root@linux ~]
tengine is stopped
[root@linux ~]
[root@linux ~]
Stopping tengine: [FAILED]
Starting tengine: [ OK ]
[root@linux ~]
tengine (pid 1734 1732) is running...
[root@linux ~]
root 1732 1 0 08:47 ? 00:00:00 nginx: master process /application/tengine/sbin/tengine -c /application/tengine/conf/tengine.conf
tengine 1734 1732 0 08:47 ? 00:00:00 nginx: worker process
[root@linux ~]
Reloading tengine: [ OK ]
[root@linux ~]
tengine (pid 1763 1732) is running...
[root@linux ~]
root 1732 1 0 08:47 ? 00:00:00 nginx: master process /application/tengine/sbin/tengine -c /application/tengine/conf/tengine.conf
tengine 1763 1732 0 08:47 ? 00:00:00 nginx: worker process
[root@linux ~]
the configuration file /application/tengine/conf/tengine.conf syntax is ok
configuration file /application/tengine/conf/tengine.conf test is successful
[root@linux ~]
[root@linux ~]
Stopping tengine: [ OK ]
Starting tengine: [ OK ]
[root@linux ~]
tengine (pid 1805 1803) is running...
[root@linux ~]
root 1803 1 0 08:48 ? 00:00:00 nginx: master process /application/tengine/sbin/tengine -c /application/tengine/conf/tengine.conf
tengine 1805 1803 0 08:48 ? 00:00:00 nginx: worker process