设为首页 收藏本站
查看: 1000|回复: 0

[经验分享] 修改resin的自动拉起

[复制链接]

尚未签到

发表于 2017-2-20 08:30:58 | 显示全部楼层 |阅读模式
#! /bin/sh
#
# See contrib/init.resin for /etc/rc.d/init.d startup script
#
# resin.sh can be called like apachectl
#
# resin.sh         -- execs resin in the foreground
# resin.sh start   -- starts resin in the background
# resin.sh stop    -- stops resin
# resin.sh restart -- restarts resin
#
# resin.sh will return a status code if the wrapper detects an error, but
# some errors, like bind exceptions or Java errors, are not detected.
#
# To install, you'll need to configure JAVA_HOME and RESIN_HOME and
# copy contrib/init.resin to /etc/rc.d/init.d/resin.  Then
# use "unix# /sbin/chkconfig resin on"
#JAVA_HOME
JAVA_HOME=/usr/local/java
export JAVA_HOME
#本脚本的绝对路径
EXEC_START="/usr/local/snsconnector/snsconnector.sh"
#执行脚本
RESIN="bin/httpd.sh"
#执行多个resin的多路径
EXEC="/usr/local/snsconnector/snsapi/resin3 /usr/local/snsconnector/testsns/resin3"
array=($EXEC)
length=${#array[@]}
echo $length
for ((i=0; i<$length; i++))
do
echo ${array[$i]}
done
#####################################################
# Find a PID for the pid file
#####################################################
for ((i=0; i<$length; i++))
do
RESIN_HOME=${array[$i]}
SNS_PIDS="$SNS_PIDS $RESIN_HOME/snsconnector.pid "
done
pids=($SNS_PIDS)
size=${#pids[@]}
echo $size
for ((i=0; i<$size; i++))
do
echo ......${pids[$i]}
done

#
SNS_TAG=snstag

if test -n "${JAVA_HOME}"; then
if test -z "${JAVA_EXE}"; then
JAVA_EXE=$JAVA_HOME/bin/java
fi
fi  
#
# trace script and simlinks to find the wrapper
#
if test -z "${RESIN_HOME}"; then
script=`/bin/ls -l $0 | awk '{ print $NF; }'`
while test -h "$script"
do
script=`/bin/ls -l $script | awk '{ print $NF; }'`
done
bin=`dirname $script`
RESIN_HOME="$bin/.."
fi  
running()
{
[ -f $1 ] || return 1
PID=$(cat $1)
echo ==========$PID==========
ps -p $PID >/dev/null 2>/dev/null || return 1
return 0
}
usage()
{
echo "Usage: $0 {start|stop|status} [ CONFIGS ... ] "
exit 1
}
[ $# -gt 0 ] || usage

ACTION=$1
MAINTE_CHECK=$2

#####################################################
# Get current script belongs to User and Group.
#####################################################
[ -z ${SCRIPT_NAME} ] && SCRIPT_NAME=httpd.sh
if [ -f ${RESIN_HOME}/bin/${SCRIPT_NAME} ]
then
CURRENT_GROUP="$(echo `ls -l ${RESIN_HOME}/bin/${SCRIPT_NAME}` | awk '{print $4}')";
CURRENT_USER="$(echo `ls -l ${RESIN_HOME}/bin/${SCRIPT_NAME}` | awk '{print $3}')";
else
echo "** ERROR: Current start service script is:"${RESIN_HOME}/bin/${SCRIPT_NAME}
echo "** ERROR: The SNS start file is not exist!"
fi
setCrontab()
{
echo "setCrontab...";
crontab_tmp=$(mktemp -p "${RESIN_HOME}/bin/")
if [ x$CURRENT_USER != x$(whoami) ]
then
echo "* * * * * su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG" '> /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 10; su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 20; su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 30; su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 40; su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 50; su - $CURRENT_USER -c '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
elif [ x$CURRENT_USER == x$(whoami) ]
then
echo "* * * * * '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 10; '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 20; '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 30; '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 40; '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
echo "* * * * * sleep 50; '"${EXEC_START} start $SNS_TAG"' > /dev/null 2>&1" >> "${crontab_tmp}"
fi
tail "${crontab_tmp}"
crontab "${crontab_tmp}"
rm -f ${crontab_tmp}
return 0
}

case "$ACTION" in
start)
for ((i=0; i<$length; i++))
do
RESIN_HOME=${array[$i]}
RUN_CMD=$RESIN_HOME/$RESIN
SNS_PID=${pids[$i]}
echo -n "$RESIN_HOME Starting snsconnector: "
if [ x$MAINTE_CHECK == x$SNS_TAG ] && [ -f "$RESIN_HOME/$SNS_TAG" ]
then
echo "Maintenance period,can't start sns service!"
exit 1
fi
if [ -f $SNS_PID ]
then
if running $SNS_PID
then
echo "Already Running!!"
echo "snsconnector running pid is:"`cat $RESIN_HOME/snsconnector.pid`
#exit 1
continue
else
# dead pid file - remove
rm -f $SNS_PID
fi
fi
if [ x$CURRENT_USER != x ] && [ x$CURRENT_USER != x$(whoami) ]
then
touch $SNS_PID
chown $CURRENT_USER:$CURRENT_GROUP $SNS_PID
su - $CURRENT_USER -c "
$RUN_CMD > /dev/null 2>&1 &
PID=\$!
disown \$PID
echo \$PID > $SNS_PID"
echo pid=$PID
echo sns_pid=$SNS_PID
elif [ x$CURRENT_USER == x$(whoami) ]
then
echo ===$RUN_CMD===
touch $SNS_PID
eval "
$RUN_CMD > /dev/null 2>&1 &
PID=\$!
disown \$PID
echo \$PID > $SNS_PID"
echo pid=$PID
echo sns_pid=$SNS_PID
fi
sleep 5
if running $SNS_PID
then
rm -f $RESIN_HOME/$SNS_TAG
echo "OK"
echo "pid is `cat $SNS_PID 2>/dev/null`"
echo "STARTED AT `date`"
else
echo "FAILED!"
fi
done
setCrontab;
exit 1
;;
stop)
for ((i=0; i<$length; i++))
do
RESIN_HOME=${array[$i]}
SNS_PID=${pids[$i]}
echo -n "$RESIN_HOME Stopping snsconnector... "
if running $SNS_PID
then
PID=`cat $RESIN_HOME/$SNS_PID 2>/dev/null`
TIMEOUT=60
while running $SNS_PID && [ $TIMEOUT -gt 0 ]
do
kill $PID 2>/dev/null
echo -n "."
sleep 1
let TIMEOUT=$TIMEOUT-1
done
[ $TIMEOUT -gt 0 ] || kill -9 $PID 2>/dev/null
rm -f $SNS_PID
echo OK
else
echo $SNS_PID snsconnector service already stopped,stop failed!
fi
touch $RESIN_HOME/$SNS_TAG
done
exit 1
;;
status)
for ((i=0; i<$length; i++))
do
RESIN_HOME=${array[$i]}
SNS_PID=${pids[$i]}
if running $SNS_PID
then
PID=`cat $SNS_PID 2>/dev/null`
echo "snsconnector(pid $PID) is running!"
else
rm -f $SNS_PID
echo "snsconnector has stoped!"
fi
done
exit 1
;;
*)
usage
;;
esac
exit 0

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-344461-1-1.html 上篇帖子: MyEclipse+resin环境搭建【转】 下篇帖子: resin-3.1相关
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表