Skip to content

Commit 3a9c539

Browse files
committed
packaging
1 parent bd3e9c0 commit 3a9c539

File tree

9 files changed

+187
-93
lines changed

9 files changed

+187
-93
lines changed

README.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ sudo yum install ./build/bdist.linux-x86_64/rpm/RPMS/noarch/clickhouse-mysql-0.0
6464
## RPM Installation
6565
**Tested on CentOS 7**
6666

67-
Packagecloud repo
67+
Packagecloud repo from [packagecloud.io](https://packagecloud.io/Altinity/clickhouse)
68+
More details on installation are available on [https://github.com/Altinity/clickhouse-rpm-install](https://github.com/Altinity/clickhouse-rpm-install)
6869
```bash
6970
curl -s https://packagecloud.io/install/repositories/altinity/clickhouse/script.rpm.sh | sudo bash
7071
```
@@ -93,30 +94,42 @@ sudo /etc/init.d/clickhouse-mysql start
9394
In case you need just to use the app - this is the most convenient way to go.
9495

9596
Install dependencies.
96-
MySQL repo for `mysql-community-devel`
97+
MySQL repo (for `mysql-community-devel`)
9798
```bash
9899
sudo yum install -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
99100
```
100-
epel (for python3)
101+
epel (for `python3`)
101102
```bash
102-
sudo yum install epel-release
103+
sudo yum install -y epel-release
104+
```
105+
106+
clickhouse-client (for `clickhouse-client`) from Packagecloud repo from [packagecloud.io](https://packagecloud.io/Altinity/clickhouse)
107+
More details on installation are available on [https://github.com/Altinity/clickhouse-rpm-install](https://github.com/Altinity/clickhouse-rpm-install)
108+
```bash
109+
curl -s https://packagecloud.io/install/repositories/altinity/clickhouse/script.rpm.sh | sudo bash
110+
```
111+
```bash
112+
sudo yum install -y clickhouse-client
103113
```
114+
104115
and direct dependencies:
105116
```bash
106-
sudo yum install mysql-community-devel
107-
sudo yum install gcc
108-
sudo yum install python34-devel python34-pip
117+
sudo yum install -y mysql-community-devel
118+
sudo yum install -y mariadb-devel
119+
sudo yum install -y gcc
120+
sudo yum install -y python34-devel python34-pip
109121
```
110122

111123
Install datareader
112124
```bash
113125
sudo pip3 install clickhouse-mysql
114126
```
115127

116-
Now we are able to call datareader as an app
128+
Now we are able to call datareader as an app - perform last installation steps - install service files, etc
117129
```bash
118130
[user@localhost ~]$ which clickhouse-mysql
119131
/usr/bin/clickhouse-mysql
132+
/usr/bin/clickhouse-mysql --install
120133
```
121134

122135
## GitHub-based Installation - Clone Sources

clickhouse-mysql.conf

-78
This file was deleted.

clickhouse-mysql.conf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
clickhouse_mysql.etc/clickhouse-mysql.conf
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# INTRODUCTION
2+
#
3+
# 1. Parameters accept both variants for naming - with '_' as a words separator or '-'.
4+
# The former is used for ENV VARS, the latter - for CLI options.
5+
# Config file accepts both, thus 'log_file' equals to 'log-file'
6+
#
7+
# 2. Boolean parameters accept case-insensitive 'yes', 'no', 'on', 'off', 1 or 0 values
8+
#
9+
# 3. Each parameter must have a value, thus
10+
# 'dry=yes' is ok,
11+
# 'dry=' is not that good, but will be interpreted as an empty line, while
12+
# 'dry' is a syntax error
13+
#
14+
# 4. Comments are '#'-only. So, php-like ';' is not accepted as a comment symbol in config file
15+
16+
#
17+
# general app section
18+
#
19+
20+
#config_file=clickhouse-mysql.conf
21+
#log_file=/var/log/clickhouse-mysql/main.log
22+
log_level=debug
23+
nice_pause=1
24+
#dry=yes
25+
#daemon=yes
26+
#pid_file=/tmp/clickhouse-client.pid
27+
binlog_position_file=/tmp/clickhouse-mysql-binlog.pos
28+
#mempool=yes
29+
mempool_max_events_num=10000
30+
#mempool_max_rows_num=
31+
mempool_max_flush_interval=60
32+
csvpool=yes
33+
csvpool_file_path_prefix=qwe_
34+
#csvpool_keep_files=yes
35+
#table_templates=yes
36+
#table_templates_with_create_database=yes
37+
#table_templates_json=yes
38+
#table_migrate=yes
39+
40+
#
41+
# src section
42+
#
43+
44+
src_server_id=1
45+
src_host=127.0.0.1
46+
#src_port=3306
47+
src_user=reader
48+
src_password=qwerty
49+
#src_schemas=db1, db2, db3
50+
#src_tables=db1.t4 t5
51+
#src_tables_where_clauses=a=1
52+
src_tables_prefixes=log_, log1_, log2_
53+
src_wait=yes
54+
src_resume=yes
55+
#src_file=
56+
#src_binlog_file=mysql-bin.000024
57+
#src_binlog_position=5307
58+
59+
#
60+
# dst section
61+
#
62+
63+
#dst_file=dst.csv
64+
dst_host=127.0.0.1
65+
#dst_port=
66+
#dst_user=default
67+
#dst_password=
68+
#dst_schema=db
69+
dst_table=logunified
70+
71+
#
72+
# converters section
73+
#
74+
75+
#column_default_value=
76+
#column_skip=
77+
#ch_converter_file=
78+
#ch_converter_class=

init.d/clickhouse-mysql renamed to clickhouse_mysql.init.d/clickhouse-mysql

+20-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
#SERVICE_NAME=$(basename $0)
1414
SERVICE_NAME=clickhouse-mysql
1515

16-
PID_FILE=/var/run/${SERVICE_NAME}/${SERVICE_NAME}.pid
17-
LOG_FILE=/var/log/${SERVICE_NAME}/${SERVICE_NAME}.log
16+
PID_FILE_DIR="/var/run/${SERVICE_NAME}"
17+
LOG_FILE_DIR="/var/log/${SERVICE_NAME}"
18+
19+
PID_FILE="${PID_FILE_DIR}/${SERVICE_NAME}.pid"
20+
LOG_FILE="${LOG_FILE_DIR}/${SERVICE_NAME}.log"
1821

1922
#RUN_CMD="python3 -m clickhouse_mysql.main --config-file=clickhouse-mysql.conf --daemon --log-file=$LOG_FILE --pid-file=$PID_FILE"
2023
RUN_CMD="/usr/bin/clickhouse-mysql --daemon --log-file=$LOG_FILE --pid-file=$PID_FILE"
@@ -79,6 +82,19 @@ function start_incapable_service()
7982
sudo -u $RUN_CMD_AS_USER bash -c "$CMD"
8083
}
8184

85+
function create_dirs()
86+
{
87+
if [ ! -d "${PID_FILE_DIR}" ]; then
88+
mkdir -p "${PID_FILE_DIR}"
89+
chown "${RUN_CMD_AS_USER}" "${PID_FILE_DIR}"
90+
fi
91+
92+
if [ ! -d "${LOG_FILE_DIR}" ]; then
93+
mkdir -p "${LOG_FILE_DIR}"
94+
chown "${RUN_CMD_AS_USER}" "${LOG_FILE_DIR}"
95+
fi
96+
}
97+
8298
function start()
8399
{
84100
if is_running; then
@@ -88,6 +104,8 @@ function start()
88104
exit 1
89105
fi
90106

107+
create_dirs
108+
91109
if ! is_file_usable "$LOG_FILE"; then
92110
echo "Log file $LOG_FILE is not writable by user $RUN_CMD_AS_USER. Please check path"
93111
exit 1

clickhouse_mysql/clioptions.py

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def options():
208208
action='store_true',
209209
help='Migrate table(s). IMPORTANT!. Target table has to be created in ClickHouse already! See --table-templates option(s) for help.'
210210
)
211+
argparser.add_argument(
212+
'--install',
213+
action='store_true',
214+
help='Install service file(s)'
215+
)
211216

212217
#
213218
# src section
@@ -400,6 +405,7 @@ def options():
400405
'table_templates_with_create_database': args.table_templates_with_create_database,
401406
'table_templates_json': args.table_templates_json,
402407
'table_migrate': args.table_migrate,
408+
'install': args.install,
403409

404410
#
405411
# src section

clickhouse_mysql/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __init__(self):
7777
'mempool_max_rows_num': self.options['mempool_max_rows_num'],
7878
'mempool_max_flush_interval': self.options['mempool_max_flush_interval'],
7979
'csvpool': self.options.get_bool('csvpool'),
80+
'install': self.options.get_bool('install'),
8081
},
8182

8283
#
@@ -217,6 +218,9 @@ def is_table_templates_with_create_database(self):
217218
def is_table_templates_json(self):
218219
return self.config['app']['table_templates_json']
219220

221+
def is_install(self):
222+
return self.config['app']['install']
223+
220224
def table_builder(self):
221225
return TableBuilder(
222226
host=self.config['table_builder']['mysql']['host'],

clickhouse_mysql/main.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import pprint
99
import json
1010
import os
11+
import pkg_resources
12+
import shutil
1113

1214
if sys.version_info < (3, 4):
1315
print("Python version is NOT OK, need 3.4 at least")
@@ -51,11 +53,55 @@ def __init__(self):
5153
logging.info(pprint.pformat(sys.path))
5254
# mp.set_start_method('forkserver')
5355

56+
@staticmethod
57+
def install():
58+
# install service file
59+
src_service_filepath = os.path.abspath(
60+
pkg_resources.resource_filename('clickhouse_mysql', '../clickhouse_mysql.init.d/clickhouse-mysql'))
61+
dst_service_dir = '/etc/init.d/'
62+
dst_service_filepath = dst_service_dir + 'clickhouse-mysql'
63+
try:
64+
print("Install service file ", src_service_filepath, ' to ', dst_service_filepath)
65+
# os.makedirs wants '/' at the end of the folder name
66+
os.makedirs(name=dst_service_dir, exist_ok=True)
67+
shutil.copy2(src_service_filepath, dst_service_filepath)
68+
except Exception as e:
69+
print(e)
70+
print('Looks like you have no permissions to write to ', dst_service_filepath)
71+
sys.exit(1)
72+
73+
# install config example file
74+
src_service_filepath = os.path.abspath(
75+
pkg_resources.resource_filename('clickhouse_mysql', '../clickhouse_mysql.etc/clickhouse-mysql.conf'))
76+
dst_service_dir = '/etc/clickhouse-mysql/'
77+
dst_service_filepath = dst_service_dir + 'clickhouse-mysql-example.conf'
78+
try:
79+
print("Install config file ", src_service_filepath, ' to ', dst_service_filepath)
80+
# os.makedirs wants '/' at the end of the folder name
81+
os.makedirs(name=dst_service_dir, exist_ok=True)
82+
shutil.copy2(src_service_filepath, dst_service_filepath)
83+
except Exception as e:
84+
print(e)
85+
print('Looks like you have no permissions to write to ', dst_service_filepath)
86+
sys.exit(1)
87+
88+
print("Ensure clickhouse user exists")
89+
os.system("useradd clickhouse")
90+
91+
print("Ensure var/run folders available")
92+
os.system("mkdir -p /var/log/clickhouse-mysql")
93+
os.system("chown clickhouse /var/log/clickhouse-mysql")
94+
os.system("mkdir -p /var/run/clickhouse-mysql")
95+
os.system("chown clickhouse /var/run/clickhouse-mysql")
96+
5497
def run(self):
5598
try:
5699
# what action are we going to do
57100

58-
if self.config.is_table_templates():
101+
if self.config.is_install():
102+
Main.install()
103+
104+
elif self.config.is_table_templates():
59105
# we are going to prepare table templates
60106
templates = self.config.table_builder().templates(self.config.is_table_templates_json())
61107

0 commit comments

Comments
 (0)