Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MariaDB as database when installing from packages #671

Merged
merged 1 commit into from Apr 24, 2017
Merged

Allow MariaDB as database when installing from packages #671

merged 1 commit into from Apr 24, 2017

Conversation

niklashagman
Copy link
Contributor

@niklashagman niklashagman commented Apr 3, 2017

MariaDB is a drop in replacement (as they like to say) for Oracle MySQL. Debian and other distributions has made it clear that MariaDB will be the default database instead of Oracle MySQL.
This patch makes it possible to install PrivacyIDEA with MariaDB.

It needs to be tested so dependencies in the package python-mysqldb does not create any conflicts or problem in PrivacyIDEA. On my Ubuntu 16.04 it does not create any problem but am not testing on a clean system.

Merging #671 into master will decrease coverage by 0.01%.
The diff coverage is n/a.
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #671      +/-   ##
==========================================
- Coverage    95.4%   95.39%   -0.02%
==========================================
Files          92      120      +28
Lines       14016    14569     +553
==========================================
+ Hits        13372    13898     +526
- Misses        644      671      +27
Impacted Files Coverage Δ
privacyidea/api/audit.py 80% <0%> (-10.15%) ⬇️
privacyidea/api/resolver.py 92.15% <0%> (-5.02%) ⬇️
privacyidea/api/lib/utils.py 92% <0%> (-3.56%) ⬇️
privacyidea/api/realm.py 98.61% <0%> (-1.39%) ⬇️
privacyidea/api/machine.py 95.69% <0%> (-0.18%) ⬇️
privacyidea/api/user.py 100% <0%> (ø) ⬆️
privacyidea/api/machineresolver.py 100% <0%> (ø) ⬆️
authmodules/__init__.py
privacyidea/lib/applications/__init__.py 100% <0%> (ø)
privacyidea/lib/machines/base.py 94% <0%> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 862aa74...0f8f5e4. Read the comment docs.

  • In the post install script we are using the mysql command line client to set up the database automatically. Can you confirm that this works out with the mariadb-server/client?
  • Today I installed a new virtual machine and did not get it to work.
apt install software-properties-common
# Installing MariaDB
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.ddg.lth.se/mariadb/repo/10.2/ubuntu xenial main'
apt update
apt install mariadb-server mariadb-client
# Installing PrivacyIDEA
add-apt-repository ppa:privacyidea/privacyidea
apt update
apt install python-privacyidea privacyideaadm
# Modify control file to allow mariadb
cd /tmp
apt download privacyidea-apache2
ar x privacyidea-apache2_2.18.1-1xenial_all.deb
sed -i s/mysql-server/mysql-server\|mariadb-server/g control
sed -i s/mysql-server/mysql-client\|mariadb-client/g control
tar czf control.tar.gz postrm md5sums postinst control conffiles
ar r privacyidea-apache2_2.18.1-1xenial_all.custom.deb debian-binary control.tar.gz data.tar.xz
# Install privacyidea-apache2
# For some reason dependencies needs to be installed before so the dpkg line below does not fail.
# Otherwise it seems like "apt install -f" is not using my custom deb file but the one from repository.
apt install apache2 libapache2-mod-wsgi python-mysqldb
dpkg -i privacyidea-apache2_2.18.1-1xenial_all.custom.deb
# -----------------------------------------
Selecting previously unselected package privacyidea-apache2.
(Reading database ... 124129 files and directories currently installed.)
Preparing to unpack privacyidea-apache2_2.18.1-1xenial_all.custom.deb ...
Unpacking privacyidea-apache2 (2.18.1-1xenial) ...
Setting up privacyidea-apache2 (2.18.1-1xenial) ...
Enabling module wsgi.
To activate the new configuration, you need to run:
service apache2 restart
Enabling module headers.
To activate the new configuration, you need to run:
service apache2 restart
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
service apache2 restart
Enabling site privacyidea.
To activate the new configuration, you need to run:
service apache2 reload
No handlers could be found for logger "privacyidea.lib.stats"
_                    _______  _______
___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
/ _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
/ .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
Encryption key written to /etc/privacyidea/enckey
The file permission of /etc/privacyidea/enckey was set to 400!
Please ensure, that it is owned by the right user.
No handlers could be found for logger "privacyidea.lib.stats"
_                    _______  _______
___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
/ _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
/ .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
<SQLAlchemy engine='mysql://pi:rYFnTdcrHe38@localhost/pi'>
Traceback (most recent call last):
File "/usr/bin/pi-manage", line 779, in <module>
manager.run()
File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 423, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 402, in handle
return handle(app, *positional_args, **kwargs)
File "/usr/lib/python2.7/dist-packages/flask_script/commands.py", line 145, in handle
return self.run(*args, **kwargs)
File "/usr/bin/pi-manage", line 428, in createdb
db.create_all()
File "/usr/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 856, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 848, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), tables=tables)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 3695, in create_all
tables=tables)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1856, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1481, in _run_visitor
**kwargs).traverse_single(element)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/visitors.py", line 121, in traverse_single
return meth(obj, **kw)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 709, in visit_metadata
[t for t in tables if self._can_create_table(t)])
File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 686, in _can_create_table
table.name, schema=table.schema)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2612, in has_table
skip_user_error_events=True).execute(st)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 906, in execute
return self._execute_text(object, multiparams, params)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
statement, parameters
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 158, in execute
result = self._query(query)
File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 308, in _query
conn.query(q)
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 820, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1002, in _read_query_result
result.read()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1285, in read
first_packet = self.connection._read_packet()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 966, in _read_packet
packet.check_error()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 394, in check_error
err.raise_mysql_exception(self._data)
File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 120, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 115, in _check_mysql_exception
raise InternalError(errno, errorvalue)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1, u'Can\'t create/write to file \'/tmp/#sql_126d_0.MAI\' (Errcode: 13 "Permission denied")') [SQL: u'DESCRIBE `smsgateway`']
No handlers could be found for logger "privacyidea.lib.stats"
_                    _______  _______
___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
/ _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
/ .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
Signing keys written to /etc/privacyidea/private.pem and /etc/privacyidea/public.pem
The file permission of /etc/privacyidea/private.pem was set to 400!
Please ensure, that it is owned by the right user.
Generating RSA private key, 2048 bit long modulus
................+++
..............................................+++
e is 65537 (0x10001)
Signature ok
subject=/CN=privacyidea
Getting Private key
Generating RSA private key, 2048 bit long modulus
.......................................+++
.................+++
e is 65537 (0x10001)
Signature ok
subject=/CN=key2
Getting Private key
No handlers could be found for logger "privacyidea.lib.stats"
Traceback (most recent call last):
File "/usr/bin/pi-manage", line 779, in <module>
manager.run()
File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 423, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 402, in handle
return handle(app, *positional_args, **kwargs)
File "/usr/lib/python2.7/dist-packages/flask_script/commands.py", line 145, in handle
return self.run(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/flask_migrate/__init__.py", line 354, in stamp
command.stamp(config, revision, sql=sql, tag=tag)
File "/usr/lib/python2.7/dist-packages/alembic/command.py", line 355, in stamp
script.run_env()
File "/usr/lib/python2.7/dist-packages/alembic/script/base.py", line 397, in run_env
util.load_python_file(self.dir, 'env.py')
File "/usr/lib/python2.7/dist-packages/alembic/util/pyfiles.py", line 81, in load_python_file
module = load_module_py(module_id, path)
File "/usr/lib/python2.7/dist-packages/alembic/util/compat.py", line 79, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "/usr/lib/privacyidea/migrations/env.py", line 87, in <module>
run_migrations_online()
File "/usr/lib/privacyidea/migrations/env.py", line 78, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/usr/lib/python2.7/dist-packages/alembic/runtime/environment.py", line 797, in run_migrations
self.get_context().run_migrations(**kw)
File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 297, in run_migrations
heads = self.get_current_heads()
File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 243, in get_current_heads
if not self._has_version_table():
File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 254, in _has_version_table
self.connection, self.version_table, self.version_table_schema)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2612, in has_table
skip_user_error_events=True).execute(st)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 906, in execute
return self._execute_text(object, multiparams, params)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
statement, parameters
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 158, in execute
result = self._query(query)
File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 308, in _query
conn.query(q)
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 820, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1002, in _read_query_result
result.read()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1285, in read
first_packet = self.connection._read_packet()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 966, in _read_packet
packet.check_error()
File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 394, in check_error
err.raise_mysql_exception(self._data)
File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 120, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 115, in _check_mysql_exception
raise InternalError(errno, errorvalue)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1, u'Can\'t create/write to file \'/tmp/#sql_126d_0.MAI\' (Errcode: 13 "Permission denied")') [SQL: 'DESCRIBE `alembic_version`']
dpkg: error processing package privacyidea-apache2 (--install):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
privacyidea-apache2
# -----------------------------------------
# mysql -u pi -prYFnTdcrHe38
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.2.5-MariaDB-10.2.5+maria~xenial-log mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use pi;
Database changed
MariaDB [pi]> show tables;
Empty set (0.00 sec)
MariaDB [pi]>
  • Thanks for your PR. Looks good anyway.

  

MariaDB is a drop in replacement (as they like to say) for Oracle MySQL. Debian and other distributions has made it clear that MariaDB will be the default database instead of Oracle MySQL.
This patch makes it possible to install PrivacyIDEA with MariaDB.
@codecov-io
Copy link

codecov-io commented Apr 3, 2017

Codecov Report

Merging #671 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #671      +/-   ##
==========================================
- Coverage    95.4%   95.39%   -0.02%     
==========================================
  Files          92      120      +28     
  Lines       14016    14569     +553     
==========================================
+ Hits        13372    13898     +526     
- Misses        644      671      +27
Impacted Files Coverage Δ
privacyidea/api/audit.py 80% <0%> (-10.15%) ⬇️
privacyidea/api/resolver.py 92.15% <0%> (-5.02%) ⬇️
privacyidea/api/lib/utils.py 92% <0%> (-3.56%) ⬇️
privacyidea/api/realm.py 98.61% <0%> (-1.39%) ⬇️
privacyidea/api/machine.py 95.69% <0%> (-0.18%) ⬇️
privacyidea/api/machineresolver.py 100% <0%> (ø) ⬆️
privacyidea/api/user.py 100% <0%> (ø) ⬆️
authmodules/__init__.py
privacyidea/lib/caconnector.py 98.05% <0%> (ø)
privacyidea/lib/subscriptions.py 93.06% <0%> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 862aa74...0f8f5e4. Read the comment docs.

@cornelinux
Copy link
Member

In the post install script we are using the mysql command line client to set up the database automatically. Can you confirm that this works out with the mariadb-server/client?

@niklashagman
Copy link
Contributor Author

niklashagman commented Apr 6, 2017

Today I installed a new virtual machine and it did work.
Had weird problem with permission on /tmp directory on a new ubuntu 16.04 installation..

apt install software-properties-common

# Installing MariaDB
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.ddg.lth.se/mariadb/repo/10.2/ubuntu xenial main'
apt update
apt install mariadb-server mariadb-client

# Installing PrivacyIDEA
add-apt-repository ppa:privacyidea/privacyidea
apt update
apt install python-privacyidea privacyideaadm

# Modify control file to allow mariadb
cd /tmp
apt download privacyidea-apache2
ar x privacyidea-apache2_2.18.1-1xenial_all.deb
tar zxf control.tar.gz
sed -i s/mysql-server/mysql-server\|mariadb-server/g control
sed -i s/mysql-server/mysql-client\|mariadb-client/g control
tar czf control.tar.gz postrm md5sums postinst control conffiles
ar r privacyidea-apache2_2.18.1-1xenial_all.custom.deb debian-binary control.tar.gz data.tar.xz

# Install privacyidea-apache2

# For some reason dependencies needs to be installed before so the dpkg line below does not fail.
# Otherwise it seems like "apt install -f" is not using my custom deb file but the one from repository.
apt install apache2 libapache2-mod-wsgi python-mysqldb
dpkg -i privacyidea-apache2_2.18.1-1xenial_all.custom.deb

# -----------------------------------------
Selecting previously unselected package privacyidea-apache2.
(Reading database ... 124129 files and directories currently installed.)
Preparing to unpack privacyidea-apache2_2.18.1-1xenial_all.custom.deb ...
Unpacking privacyidea-apache2 (2.18.1-1xenial) ...
Setting up privacyidea-apache2 (2.18.1-1xenial) ...
Enabling module wsgi.
To activate the new configuration, you need to run:
  service apache2 restart
Enabling module headers.
To activate the new configuration, you need to run:
  service apache2 restart
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  service apache2 restart
Enabling site privacyidea.
To activate the new configuration, you need to run:
  service apache2 reload
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   

Encryption key written to /etc/privacyidea/enckey
The file permission of /etc/privacyidea/enckey was set to 400!
Please ensure, that it is owned by the right user.   
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   
<SQLAlchemy engine='mysql://pi:rYFnTdcrHe38@localhost/pi'>
Traceback (most recent call last):
  File "/usr/bin/pi-manage", line 779, in <module>
    manager.run()
  File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 423, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 402, in handle
    return handle(app, *positional_args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/flask_script/commands.py", line 145, in handle
    return self.run(*args, **kwargs)
  File "/usr/bin/pi-manage", line 428, in createdb
    db.create_all()
  File "/usr/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 856, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
  File "/usr/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 848, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), tables=tables)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 3695, in create_all
    tables=tables)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1856, in _run_visitor
    conn._run_visitor(visitorcallable, element, **kwargs)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1481, in _run_visitor
    **kwargs).traverse_single(element)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/visitors.py", line 121, in traverse_single
    return meth(obj, **kw)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 709, in visit_metadata
    [t for t in tables if self._can_create_table(t)])
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 686, in _can_create_table
    table.name, schema=table.schema)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2612, in has_table
    skip_user_error_events=True).execute(st)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 906, in execute
    return self._execute_text(object, multiparams, params)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
    statement, parameters
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 158, in execute
    result = self._query(query)
  File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 308, in _query
    conn.query(q)
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 820, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1002, in _read_query_result
    result.read()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1285, in read
    first_packet = self.connection._read_packet()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 966, in _read_packet
    packet.check_error()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 394, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 120, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 115, in _check_mysql_exception
    raise InternalError(errno, errorvalue)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1, u'Can\'t create/write to file \'/tmp/#sql_126d_0.MAI\' (Errcode: 13 "Permission denied")') [SQL: u'DESCRIBE `smsgateway`']
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   
Signing keys written to /etc/privacyidea/private.pem and /etc/privacyidea/public.pem
The file permission of /etc/privacyidea/private.pem was set to 400!
Please ensure, that it is owned by the right user.
Generating RSA private key, 2048 bit long modulus
................+++
..............................................+++
e is 65537 (0x10001)
Signature ok
subject=/CN=privacyidea
Getting Private key
Generating RSA private key, 2048 bit long modulus
.......................................+++
.................+++
e is 65537 (0x10001)
Signature ok
subject=/CN=key2
Getting Private key
No handlers could be found for logger "privacyidea.lib.stats"
Traceback (most recent call last):
  File "/usr/bin/pi-manage", line 779, in <module>
    manager.run()
  File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 423, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 402, in handle
    return handle(app, *positional_args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/flask_script/commands.py", line 145, in handle
    return self.run(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/flask_migrate/__init__.py", line 354, in stamp
    command.stamp(config, revision, sql=sql, tag=tag)
  File "/usr/lib/python2.7/dist-packages/alembic/command.py", line 355, in stamp
    script.run_env()
  File "/usr/lib/python2.7/dist-packages/alembic/script/base.py", line 397, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/usr/lib/python2.7/dist-packages/alembic/util/pyfiles.py", line 81, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/lib/python2.7/dist-packages/alembic/util/compat.py", line 79, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "/usr/lib/privacyidea/migrations/env.py", line 87, in <module>
    run_migrations_online()
  File "/usr/lib/privacyidea/migrations/env.py", line 78, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/lib/python2.7/dist-packages/alembic/runtime/environment.py", line 797, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 297, in run_migrations
    heads = self.get_current_heads()
  File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 243, in get_current_heads
    if not self._has_version_table():
  File "/usr/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 254, in _has_version_table
    self.connection, self.version_table, self.version_table_schema)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2612, in has_table
    skip_user_error_events=True).execute(st)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 906, in execute
    return self._execute_text(object, multiparams, params)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
    statement, parameters
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 158, in execute
    result = self._query(query)
  File "/usr/lib/python2.7/dist-packages/pymysql/cursors.py", line 308, in _query
    conn.query(q)
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 820, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1002, in _read_query_result
    result.read()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 1285, in read
    first_packet = self.connection._read_packet()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 966, in _read_packet
    packet.check_error()
  File "/usr/lib/python2.7/dist-packages/pymysql/connections.py", line 394, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 120, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "/usr/lib/python2.7/dist-packages/pymysql/err.py", line 115, in _check_mysql_exception
    raise InternalError(errno, errorvalue)
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1, u'Can\'t create/write to file \'/tmp/#sql_126d_0.MAI\' (Errcode: 13 "Permission denied")') [SQL: 'DESCRIBE `alembic_version`']
dpkg: error processing package privacyidea-apache2 (--install):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 privacyidea-apache2
# -----------------------------------------

# mysql -u pi -prYFnTdcrHe38
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.2.5-MariaDB-10.2.5+maria~xenial-log mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use pi;
Database changed
MariaDB [pi]> show tables;
Empty set (0.00 sec)

MariaDB [pi]> 

Solution to problem above is to run this

chmod 0777 /tmp
# Then again dpkg -i privacyidea-apache2_2.18.1-1xenial_all.custom.deb
dpkg -i privacyidea-apache2_2.18.1-1xenial_all.custom.deb

# -----------------------------------------
(Reading database ... 124140 files and directories currently installed.)
Preparing to unpack privacyidea-apache2_2.18.1-1xenial_all.custom.deb ...
Unpacking privacyidea-apache2 (2.18.1-1xenial) over (2.18.1-1xenial) ...
Setting up privacyidea-apache2 (2.18.1-1xenial) ...
useradd: user 'privacyidea' already exists
Module wsgi already enabled
Module headers already enabled
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Module socache_shmcb already enabled
Module ssl already enabled
Enabling site privacyidea.
To activate the new configuration, you need to run:
  service apache2 reload
ln: failed to create symbolic link '/etc/ssl/certs/privacyidea-bundle.crt': File exists
ln: failed to create symbolic link '/etc/ssl/private/privacyidea.key': File exists
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   

The file 
	/etc/privacyidea/enckey
already exist. We do not overwrite it!
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   
<SQLAlchemy engine='mysql://pi:rYFnTdcrHe38@localhost/pi'>
No handlers could be found for logger "privacyidea.lib.stats"

             _                    _______  _______
   ___  ____(_)  _____ _______ __/  _/ _ \/ __/ _ |
  / _ \/ __/ / |/ / _ `/ __/ // // // // / _// __ |
 / .__/_/ /_/|___/\_,_/\__/\_, /___/____/___/_/ |_|
/_/                       /___/
   
The file 
	/etc/privacyidea/private.pem
already exist. We do not overwrite it!
No handlers could be found for logger "privacyidea.lib.stats"
No handlers could be found for logger "privacyidea.lib.stats"

# -----------------------------------------
# mysql -u pi -prYFnTdcrHe38
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.2.5-MariaDB-10.2.5+maria~xenial-log mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use pi;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [pi]> show tables;
+-----------------------+
| Tables_in_pi          |
+-----------------------+
| admin                 |
| alembic_version       |
| caconnector           |
| caconnectorconfig     |
| challenge             |
| clientapplication     |
| config                |
| eventhandler          |
| eventhandlercondition |
| eventhandleroption    |
| machineresolver       |
| machineresolverconfig |
| machinetoken          |
| machinetokenoptions   |
| passwordreset         |
| pidea_audit           |
| policy                |
| radiusserver          |
| realm                 |
| resolver              |
| resolverconfig        |
| resolverrealm         |
| smsgateway            |
| smsgatewayoption      |
| smtpserver            |
| subscription          |
| token                 |
| tokeninfo             |
| tokenrealm            |
+-----------------------+
29 rows in set (0.00 sec)

MariaDB [pi]> 

@cornelinux
Copy link
Member

Thanks for your PR. Looks good anyway.

@cornelinux cornelinux merged commit 20e0d79 into privacyidea:master Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants