看canal的时候看了下deploy的脚本,发现很多系统都大同小异
如果是需要debug,就需要开启调试端口
if [ "$1" = "debug" ]; then DEBUG_PORT=$2 DEBUG_SUSPEND="n" JAVA_DEBUG_OPT="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=$DEBUG_SUSPEND" fi
按照系统位数设置不同的jvm参数
str=`file -L $JAVA | grep 64-bit` if [ -n "$str" ]; then JAVA_OPTS="-server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss256k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError" else JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m " fi
启动程序,1 是正确,正确则将日志写入log中,2表示不正确,则输出,最后的&表示后台执行
第二行表示将进程号打印到canal.pid文件中,以供关闭时kill该进程
$JAVA $JAVA_OPTS $JAVA_DEBUG_OPT $CANAL_OPTS -classpath .:$CLASSPATH com.alibaba.otter.canal.deployer.CanalLauncher 1>>$base/logs/canal/canal.log 2>&1 & echo $! > $base/bin/canal.pid
结束的程序,找到pid文件,kill进程
base=`dirname $0`/.. pidfile=$base/bin/canal.pid if [ ! -f "$pidfile" ];then echo "canal is not running. exists" exit fi pid=`cat $pidfile` if [ "$pid" == "" ] ; then pid=`get_pid "appName=otter-canal-example"` fi echo -e "`hostname`: stopping canal $pid ... " kill $pid