Created
August 7, 2018 11:14
-
-
Save qknight/c63367bfdee41de32490d9e7fd9f4e75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
we want to use the environment you define below to pass in the local.py which contains the configuration for the database for django. | |
however, you code uses the preStart which we can't support in nixcloud-webservices in a similar way so we play with the environment variable called PYTHONPATH like shown below. | |
problem: our local.py configuration is never used, so we kindly ask you what we do wrong. | |
we also tried `manage.py`'s command line arguments as --pythonpath and --settings but we can't get them to work as python errors out because of not finding a module. | |
# our code | |
export PYTHONPATH=/nix/store/rk42r3j6rb1q8bb56fx5cy0rhab96ccz-taiga-back-config-package/settings/:/nix/store/5l90s5r5aj1ykgg2g500vkl8a305v5vi-python3-3.6.5-env/lib/python3.6/site-packages/:$PTHONPATH | |
/nix/store/k71fs76g4j7pynq4n7iz30gab7wsql0p-taiga-back-3.3.14/bin/manage.py migrate --noinput | |
Trying import local.py settings... | |
Trying import development.py settings... | |
Traceback (most recent call last): | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection | |
self.connect() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect | |
self.connection = self.get_new_connection(conn_params) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection | |
connection = Database.connect(**conn_params) | |
File "/nix/store/69k55a25bwd8k0h728nknbszbfi5w9ps-python3.6-psycopg2-2.7.1/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect | |
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) | |
psycopg2.OperationalError: could not connect to server: No such file or directory | |
Is the server running locally and accepting | |
connections on Unix domain socket "/tmp/.s.PGSQL.5432"? | |
The above exception was the direct cause of the following exception: | |
Traceback (most recent call last): | |
File "/nix/store/k71fs76g4j7pynq4n7iz30gab7wsql0p-taiga-back-3.3.14/bin/.manage.py-wrapped", line 30, in <module> | |
execute_from_command_line(sys.argv) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line | |
utility.execute() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute | |
self.fetch_command(subcommand).run_from_argv(self.argv) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv | |
self.execute(*args, **cmd_options) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute | |
output = self.handle(*args, **options) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 83, in handle | |
executor = MigrationExecutor(connection, self.migration_progress_callback) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/migrations/executor.py", line 20, in __init__ | |
self.loader = MigrationLoader(self.connection) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/migrations/loader.py", line 52, in __init__ | |
self.build_graph() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph | |
self.applied_migrations = recorder.applied_migrations() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations | |
self.ensure_schema() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema | |
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()): | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor | |
return self._cursor() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor | |
self.ensure_connection() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection | |
self.connect() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__ | |
six.reraise(dj_exc_type, dj_exc_value, traceback) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise | |
raise value.with_traceback(tb) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection | |
self.connect() | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect | |
self.connection = self.get_new_connection(conn_params) | |
File "/nix/store/5ciir3vcw8s8rlkgn1ijbh7mmfyhxa4q-python3.6-Django-1.11.13/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection | |
connection = Database.connect(**conn_params) | |
File "/nix/store/69k55a25bwd8k0h728nknbszbfi5w9ps-python3.6-psycopg2-2.7.1/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect | |
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) | |
django.db.utils.OperationalError: could not connect to server: No such file or directory | |
Is the server running locally and accepting | |
connections on Unix domain socket "/tmp/.s.PGSQL.5432"? | |
# your code | |
+ systemd.services.taiga = { | |
+ description = "Taiga Platform Server (Backend)"; | |
+ | |
+ wantedBy = [ "multi-user.target" ]; | |
+ requires = [ "network-online.target" ] ++ optional useLocalDatabase "postgresql.service"; | |
+ after = [ "network-online.target" ] ++ optional useLocalDatabase "postgresql.service"; | |
+ before = [ "nginx.service" ]; | |
+ | |
+ environment = let | |
+ python = pkgs.python3; | |
+ penv = python.buildEnv.override { | |
+ extraLibs = [ | |
+ taiga-back | |
+ pkgs.python3Packages.gunicorn | |
+ pkgs.python3Packages.gevent | |
+ ]; | |
+ }; | |
+ in { | |
+ PYTHONPATH = "${taigaBackConfigPkg}:${penv}/${python.sitePackages}/"; | |
+ }; | |
+ | |
+ serviceConfig = { | |
+ User = cfg.user; | |
+ Group = cfg.group; | |
+ WorkingDirectory = cfg.statePath; | |
+ ExecStart = if cfg.enableWsgi then '' | |
+ ${pkgs.python3Packages.gunicorn}/bin/gunicorn taiga.wsgi \ | |
+ -u ${cfg.user} \ | |
+ -g ${cfg.group} \ | |
+ -k gevent \ | |
+ --name gunicorn-taiga \ | |
+ --log-level ${if cfg.enableDebug then "debug" else "info"} \ | |
+ --workers ${toString cfg.wsgiWorkers} \ | |
+ --pid ${cfg.statePath}/gunicorn-taiga.pid \ | |
+ --bind 127.0.0.1:8000 | |
+ '' else '' | |
+ ${taiga-back}/bin/manage.py runserver --nostatic "127.0.0.1:8000" | |
+ ''; | |
+ Restart = "always"; | |
+ PermissionsStartOnly = true; | |
+ PrivateDevices = true; | |
+ PrivateTmp = true; | |
+ TimeoutSec = 300; | |
+ }; | |
+ | |
+ preStart = '' | |
+ set -x | |
+ cd ${taiga-back}/lib/python3.5/site-packages/taiga | |
+ # BACK | |
+ if ! [ -e ${cfg.statePath}/.back-initialized ]; then | |
+ ${taiga-back}/bin/manage.py compilemessages | |
+ ${taiga-back}/bin/manage.py collectstatic --noinput | |
+ touch ${cfg.statePath}/.back-initialized | |
+ fi | |
+ ${optionalString useLocalDatabase '' | |
+ # LOCAL DATABASE | |
+ if ! [ -e ${cfg.statePath}/.db-created ]; then | |
+ ${config.services.postgresql.package}/bin/createuser ${cfg.database.user} | |
+ ${config.services.postgresql.package}/bin/createdb ${cfg.database.name} -O ${cfg.database.user} | |
+ touch ${cfg.statePath}/.db-created | |
+ fi | |
+ ''} | |
+ # SEED DATABASE | |
+ if ! [ -e ${cfg.statePath}/.db-seeded ]; then | |
+ ${taiga-back}/bin/manage.py migrate --noinput | |
+ ${taiga-back}/bin/manage.py loaddata initial_user | |
+ ${taiga-back}/bin/manage.py loaddata initial_project_templates | |
+# if ! [ -e ${cfg.statePath}/.db-sampledata ]; then | |
+# ${taiga-back}/bin/manage.py sample_data | |
+# touch ${cfg.statePath}/.db-sampledata | |
+# fi | |
+ touch ${cfg.statePath}/.db-seeded | |
+ fi | |
+ chown ${cfg.user}:${cfg.group} -R ${cfg.statePath} | |
+ chmod u+rw,g+r,o-rwx -R ${cfg.statePath} | |
+ ''; | |
+ }; | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment