mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #801 , support canal docker
This commit is contained in:
19
docker/image/alidata/init/02init-sshd.sh
Executable file
19
docker/image/alidata/init/02init-sshd.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# set port
|
||||
if [ -z "${SSHD_PORT}" ] ; then
|
||||
SSHD_PORT=22
|
||||
[ "${DOCKER_DEPLOY_TYPE}" = "HOST" ] && SSHD_PORT=2222
|
||||
fi
|
||||
|
||||
sed -r -i '/^OPTIONS=/ d' /etc/sysconfig/sshd
|
||||
echo 'OPTIONS="-p '"${SSHD_PORT}"'"' >> /etc/sysconfig/sshd
|
||||
|
||||
# set admin ssh pulic key
|
||||
if [ "${USE_ADMIN_PASSAGE}" = "YES" ] ; then
|
||||
echo "set admin passage"
|
||||
mkdir -p /home/admin/.ssh
|
||||
chown admin:admin /home/admin/.ssh
|
||||
chown admin:admin /home/admin/.ssh/authorized_keys
|
||||
chmod 644 /home/admin/.ssh/authorized_keys
|
||||
fi
|
||||
66
docker/image/alidata/init/fix-hosts.py
Executable file
66
docker/image/alidata/init/fix-hosts.py
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#****************************************************************#
|
||||
# Create Date: 2017-01-06 17:58
|
||||
#***************************************************************#
|
||||
|
||||
import socket
|
||||
import shutil
|
||||
from time import gmtime, strftime
|
||||
|
||||
# get host_name
|
||||
host_name = socket.gethostname()
|
||||
tmp_file = "/tmp/.lark-fix-host.hosts"
|
||||
host_file = "/etc/hosts"
|
||||
bak_file_name = "/tmp/hosts-fix-bak.%s" % ( strftime("%Y-%m-%d_%H-%M-%S", gmtime()) )
|
||||
|
||||
# load /etc/hosts file context
|
||||
FH = open(host_file,"r")
|
||||
file_lines = [ i.rstrip() for i in FH.readlines()]
|
||||
FH.close()
|
||||
file_lines_reverse = file_lines[::-1]
|
||||
new_lines = []
|
||||
bad_lines = []
|
||||
last_match_line = ""
|
||||
|
||||
for line in file_lines_reverse:
|
||||
if line.find(host_name) < 0: # 不匹配的行直接跳过
|
||||
new_lines.append(line + "\n")
|
||||
continue
|
||||
|
||||
cols = line.split()
|
||||
new_cols = []
|
||||
if cols[0].startswith("#"): # 跳过已经注释掉的行
|
||||
new_lines.append(line + "\n")
|
||||
continue
|
||||
for col in cols:
|
||||
if not col == host_name: # 跳过不匹配的列
|
||||
new_cols.append(col)
|
||||
continue
|
||||
|
||||
if cols[0] == "127.0.0.1": # 如果第一列是 127.0.0.1 就跳过匹配的列, 防止 hostname -i 返回 127.0.0.1
|
||||
continue
|
||||
|
||||
# 如果已经发现过匹配的列, 就丢掉重复的列
|
||||
if not len(last_match_line) == 0:
|
||||
continue
|
||||
|
||||
new_cols.append(col)
|
||||
last_match_line = line
|
||||
|
||||
# 跳过 xx.xx.xx.xx hostname 这样的重复列
|
||||
if len(new_cols) == 1:
|
||||
continue
|
||||
|
||||
new_l = "%s\n" % " ".join(new_cols)
|
||||
new_lines.append(new_l)
|
||||
|
||||
# save tmp hosts
|
||||
|
||||
FH2=file(tmp_file,"w+")
|
||||
FH2.writelines( new_lines[::-1])
|
||||
FH2.close()
|
||||
|
||||
# mv to /etc/hosts
|
||||
shutil.copy(host_file, bak_file_name)
|
||||
shutil.move(tmp_file, host_file)
|
||||
Reference in New Issue
Block a user