{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/mongodb/pulls/comments/56190867","id":56190867,"diff_hunk":"@@ -177,21 +177,92 @@ function run_mongod_supervisor() {\n   ${CONTAINER_SCRIPTS_PATH}/replica_supervisor.sh 2>&1 &\n }\n \n-# mongo_create_users creates the MongoDB admin user and the database user\n-# configured by MONGODB_USER\n-function mongo_create_users() {\n-  mongo ${MONGODB_DATABASE} --eval \"db.addUser({user: '${MONGODB_USER}', pwd: '${MONGODB_PASSWORD}', roles: [ 'readWrite' ]})\"\n+# mongo_create_admin creates the MongoDB admin user with password: MONGODB_ADMIN_PASSWORD\n+# $1 - login parameters for mongo (optional)\n+# $2 - host where to connect (localhost by default)\n+function mongo_create_admin() {\n+  if [[ -z \"${MONGODB_ADMIN_PASSWORD:-}\" ]]; then\n+    echo \"=> MONGODB_ADMIN_PASSWORD is not set. Authentication can not be set up.\"\n+    exit 1\n+  fi\n+\n+  # Set admin password\n+  set +e\n+  mongo admin ${1:-} --host ${2:-\"localhost\"} --eval \"db.addUser({user: 'admin', pwd: '${MONGODB_ADMIN_PASSWORD}', roles: ['dbAdminAnyDatabase', 'userAdminAnyDatabase' , 'readWriteAnyDatabase','clusterAdmin' ]});\"\n+  local result=$?\n+  set -e\n+\n+  if [[ ${result} -ne 0 ]]; then\n+    echo \"=> Failed to create MongoDB admin user.\"\n+    exit 1\n+  fi\n+\n+  touch ${MONGODB_DATADIR}/.mongodb_datadir_initialized","path":"2.4/root/usr/share/container-scripts/mongodb/common.sh","position":28,"original_position":28,"commit_id":"3ce6458a8b18e6de7f0987a2823519bcf76cb1c4","original_commit_id":"3ce6458a8b18e6de7f0987a2823519bcf76cb1c4","user":{"login":"rhcarvalho","id":88819,"avatar_url":"https://avatars.githubusercontent.com/u/88819?v=3","gravatar_id":"","url":"https://api.github.com/users/rhcarvalho","html_url":"https://github.com/rhcarvalho","followers_url":"https://api.github.com/users/rhcarvalho/followers","following_url":"https://api.github.com/users/rhcarvalho/following{/other_user}","gists_url":"https://api.github.com/users/rhcarvalho/gists{/gist_id}","starred_url":"https://api.github.com/users/rhcarvalho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhcarvalho/subscriptions","organizations_url":"https://api.github.com/users/rhcarvalho/orgs","repos_url":"https://api.github.com/users/rhcarvalho/repos","events_url":"https://api.github.com/users/rhcarvalho/events{/privacy}","received_events_url":"https://api.github.com/users/rhcarvalho/received_events","type":"User","site_admin":false},"body":":skull: This is problematic, but don't worry we have a solution :bulb: \r\n\r\nThe existence of this file communicates that the database has been initialized. Now that both functions touch the same file, we're creating a situation where we declare that it is initialized before all users are created.\r\n\r\nThe file is checked here [run-mongod#L76](https://github.com/openshift/mongodb/blob/ed4299ed23620afe23fff09f9da1d373cfcedd4a/2.4/root/usr/bin/run-mongod#L76). With this change, if only one user is created, and then there's a crash, upon restart we'll assume that the database has been initialized when it actually haven't completed fully.\r\n\r\nTo fix the problem, we should move this line outside of the functions and have it only once [after the users are created](https://github.com/openshift/mongodb/blob/ed4299ed23620afe23fff09f9da1d373cfcedd4a/2.4/root/usr/bin/run-mongod#L81).","created_at":"2016-03-15T16:10:43Z","updated_at":"2016-03-15T16:10:43Z","html_url":"https://github.com/openshift/mongodb/pull/136#discussion_r56190867","pull_request_url":"https://api.github.com/repos/openshift/mongodb/pulls/136","_links":{"self":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/comments/56190867"},"html":{"href":"https://github.com/openshift/mongodb/pull/136#discussion_r56190867"},"pull_request":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/136"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/mongodb/pulls/136","id":61915118,"html_url":"https://github.com/openshift/mongodb/pull/136","diff_url":"https://github.com/openshift/mongodb/pull/136.diff","patch_url":"https://github.com/openshift/mongodb/pull/136.patch","issue_url":"https://api.github.com/repos/openshift/mongodb/issues/136","number":136,"state":"open","locked":false,"title":"Changes in user management functions.","user":{"login":"omron93","id":3758789,"avatar_url":"https://avatars.githubusercontent.com/u/3758789?v=3","gravatar_id":"","url":"https://api.github.com/users/omron93","html_url":"https://github.com/omron93","followers_url":"https://api.github.com/users/omron93/followers","following_url":"https://api.github.com/users/omron93/following{/other_user}","gists_url":"https://api.github.com/users/omron93/gists{/gist_id}","starred_url":"https://api.github.com/users/omron93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omron93/subscriptions","organizations_url":"https://api.github.com/users/omron93/orgs","repos_url":"https://api.github.com/users/omron93/repos","events_url":"https://api.github.com/users/omron93/events{/privacy}","received_events_url":"https://api.github.com/users/omron93/received_events","type":"User","site_admin":false},"body":"This PR splits `mongo_create_users` function into two functions: `mongo_create_admin` and `mongo_create_user`. This allow to create for example only admin user.\r\n\r\nIn this functions there is also ability to specify a host where to connect to create MongoDB users and also adds a checks for env. variable needed for creating user.\r\n\r\nThis PR is a part of #112 ","created_at":"2016-03-07T13:13:30Z","updated_at":"2016-03-15T16:10:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9fb83fae996fe51b9ded8f5321131f08292ecf19","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/mongodb/pulls/136/commits","review_comments_url":"https://api.github.com/repos/openshift/mongodb/pulls/136/comments","review_comment_url":"https://api.github.com/repos/openshift/mongodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/mongodb/issues/136/comments","statuses_url":"https://api.github.com/repos/openshift/mongodb/statuses/3ce6458a8b18e6de7f0987a2823519bcf76cb1c4","head":{"label":"omron93:splitCreateUser","ref":"splitCreateUser","sha":"3ce6458a8b18e6de7f0987a2823519bcf76cb1c4","user":{"login":"omron93","id":3758789,"avatar_url":"https://avatars.githubusercontent.com/u/3758789?v=3","gravatar_id":"","url":"https://api.github.com/users/omron93","html_url":"https://github.com/omron93","followers_url":"https://api.github.com/users/omron93/followers","following_url":"https://api.github.com/users/omron93/following{/other_user}","gists_url":"https://api.github.com/users/omron93/gists{/gist_id}","starred_url":"https://api.github.com/users/omron93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omron93/subscriptions","organizations_url":"https://api.github.com/users/omron93/orgs","repos_url":"https://api.github.com/users/omron93/repos","events_url":"https://api.github.com/users/omron93/events{/privacy}","received_events_url":"https://api.github.com/users/omron93/received_events","type":"User","site_admin":false},"repo":{"id":36733508,"name":"mongodb","full_name":"omron93/mongodb","owner":{"login":"omron93","id":3758789,"avatar_url":"https://avatars.githubusercontent.com/u/3758789?v=3","gravatar_id":"","url":"https://api.github.com/users/omron93","html_url":"https://github.com/omron93","followers_url":"https://api.github.com/users/omron93/followers","following_url":"https://api.github.com/users/omron93/following{/other_user}","gists_url":"https://api.github.com/users/omron93/gists{/gist_id}","starred_url":"https://api.github.com/users/omron93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omron93/subscriptions","organizations_url":"https://api.github.com/users/omron93/orgs","repos_url":"https://api.github.com/users/omron93/repos","events_url":"https://api.github.com/users/omron93/events{/privacy}","received_events_url":"https://api.github.com/users/omron93/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/omron93/mongodb","description":"","fork":true,"url":"https://api.github.com/repos/omron93/mongodb","forks_url":"https://api.github.com/repos/omron93/mongodb/forks","keys_url":"https://api.github.com/repos/omron93/mongodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/omron93/mongodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/omron93/mongodb/teams","hooks_url":"https://api.github.com/repos/omron93/mongodb/hooks","issue_events_url":"https://api.github.com/repos/omron93/mongodb/issues/events{/number}","events_url":"https://api.github.com/repos/omron93/mongodb/events","assignees_url":"https://api.github.com/repos/omron93/mongodb/assignees{/user}","branches_url":"https://api.github.com/repos/omron93/mongodb/branches{/branch}","tags_url":"https://api.github.com/repos/omron93/mongodb/tags","blobs_url":"https://api.github.com/repos/omron93/mongodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/omron93/mongodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/omron93/mongodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/omron93/mongodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/omron93/mongodb/statuses/{sha}","languages_url":"https://api.github.com/repos/omron93/mongodb/languages","stargazers_url":"https://api.github.com/repos/omron93/mongodb/stargazers","contributors_url":"https://api.github.com/repos/omron93/mongodb/contributors","subscribers_url":"https://api.github.com/repos/omron93/mongodb/subscribers","subscription_url":"https://api.github.com/repos/omron93/mongodb/subscription","commits_url":"https://api.github.com/repos/omron93/mongodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/omron93/mongodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/omron93/mongodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/omron93/mongodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/omron93/mongodb/contents/{+path}","compare_url":"https://api.github.com/repos/omron93/mongodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/omron93/mongodb/merges","archive_url":"https://api.github.com/repos/omron93/mongodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/omron93/mongodb/downloads","issues_url":"https://api.github.com/repos/omron93/mongodb/issues{/number}","pulls_url":"https://api.github.com/repos/omron93/mongodb/pulls{/number}","milestones_url":"https://api.github.com/repos/omron93/mongodb/milestones{/number}","notifications_url":"https://api.github.com/repos/omron93/mongodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/omron93/mongodb/labels{/name}","releases_url":"https://api.github.com/repos/omron93/mongodb/releases{/id}","deployments_url":"https://api.github.com/repos/omron93/mongodb/deployments","created_at":"2015-06-02T13:03:57Z","updated_at":"2016-03-07T11:58:29Z","pushed_at":"2016-03-14T19:04:33Z","git_url":"git://github.com/omron93/mongodb.git","ssh_url":"git@github.com:omron93/mongodb.git","clone_url":"https://github.com/omron93/mongodb.git","svn_url":"https://github.com/omron93/mongodb","homepage":null,"size":211,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"5424db6faf71e3accbd851ae5457bee0263a6faf","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":31970825,"name":"mongodb","full_name":"openshift/mongodb","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/mongodb","description":"","fork":false,"url":"https://api.github.com/repos/openshift/mongodb","forks_url":"https://api.github.com/repos/openshift/mongodb/forks","keys_url":"https://api.github.com/repos/openshift/mongodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/mongodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/mongodb/teams","hooks_url":"https://api.github.com/repos/openshift/mongodb/hooks","issue_events_url":"https://api.github.com/repos/openshift/mongodb/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/mongodb/events","assignees_url":"https://api.github.com/repos/openshift/mongodb/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/mongodb/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/mongodb/tags","blobs_url":"https://api.github.com/repos/openshift/mongodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/mongodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/mongodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/mongodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/mongodb/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/mongodb/languages","stargazers_url":"https://api.github.com/repos/openshift/mongodb/stargazers","contributors_url":"https://api.github.com/repos/openshift/mongodb/contributors","subscribers_url":"https://api.github.com/repos/openshift/mongodb/subscribers","subscription_url":"https://api.github.com/repos/openshift/mongodb/subscription","commits_url":"https://api.github.com/repos/openshift/mongodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/mongodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/mongodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/mongodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/mongodb/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/mongodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/mongodb/merges","archive_url":"https://api.github.com/repos/openshift/mongodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/mongodb/downloads","issues_url":"https://api.github.com/repos/openshift/mongodb/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/mongodb/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/mongodb/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/mongodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/mongodb/labels{/name}","releases_url":"https://api.github.com/repos/openshift/mongodb/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/mongodb/deployments","created_at":"2015-03-10T17:15:19Z","updated_at":"2016-03-14T18:11:52Z","pushed_at":"2016-03-15T15:20:13Z","git_url":"git://github.com/openshift/mongodb.git","ssh_url":"git@github.com:openshift/mongodb.git","clone_url":"https://github.com/openshift/mongodb.git","svn_url":"https://github.com/openshift/mongodb","homepage":null,"size":263,"stargazers_count":6,"watchers_count":6,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":19,"forks":49,"open_issues":19,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/136"},"html":{"href":"https://github.com/openshift/mongodb/pull/136"},"issue":{"href":"https://api.github.com/repos/openshift/mongodb/issues/136"},"comments":{"href":"https://api.github.com/repos/openshift/mongodb/issues/136/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/136/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/mongodb/pulls/136/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/mongodb/statuses/3ce6458a8b18e6de7f0987a2823519bcf76cb1c4"}}}}