You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0KB

  1. #' Clear the default credentials in the webclient
  2. #'
  3. #' Clear the default credentials in the webclient
  4. #'
  5. #' @export
  6. clear_webclient <- function()
  7. {
  8. "/var/www/html/webclient/js-i2b2/i2b2_ui_config.js" %>%
  9. readLines %>%
  10. stringr::str_c(collapse = "\n") %>%
  11. stringr::str_replace("demo", "") %>%
  12. stringr::str_replace("demouser", "") %>%
  13. write("/var/www/html/webclient/js-i2b2/i2b2_ui_config.js")
  14. }
  15. #' Set the permissions for the webclient and wildfly folders
  16. #'
  17. #' Set the permissions wildfly:wildfly +rwx and setgid to the webclient and wildfly folders
  18. #'
  19. #' @export
  20. set_permissions <- function()
  21. {
  22. system("chown wildfly:wildfly /var/www/html -R")
  23. system("chmod 775 /var/www/html -R")
  24. system("chmod 775 /opt/wildfly-10.0.0.Final -R")
  25. system("chmod g+s /var/www/html -R")
  26. system("chmod g+s /opt/wildfly-10.0.0.Final -R")
  27. }
  28. #' Create system and database admin accounts
  29. #'
  30. #' Create system and database admin accounts
  31. #'
  32. #' Create a system and database admin accounts
  33. #' The name of the account is i2b2admin by default
  34. #' The shared password can be provided, or randomly generated (length = 8 characters by default)
  35. #' The system account belongs in the users and wildfly groups
  36. #'
  37. #' @param admin Name of the admin account to create
  38. #' @param pass An arbitrary password if provided, i2b2admin by default
  39. #' @param pass_length The length of the generated password, 8 characters by default
  40. #' @return The generated password
  41. #' @export
  42. create_admin <- function(admin = "i2b2admin", pass= NULL, pass_length = 8)
  43. {
  44. # Generate a new password of default length 10
  45. if (is.null(pass))
  46. pass <- create_password(pass_length)
  47. # Create the system user
  48. system(stringr::str_c("useradd ", admin, " -g users -G wildfly -m"))
  49. system(stringr::str_c("echo \"", admin, ":", pass, "\" | chpasswd"))
  50. print(stringr::str_c(admin, " system account created with password: ", pass))
  51. # Connect to the db
  52. con <- RPostgreSQL::dbConnect(RPostgreSQL::PostgreSQL())
  53. # Create the database user and its database
  54. RPostgreSQL::dbGetQuery(con, stringr::str_c("create user ", admin, " with superuser createrole createdb password '", pass, "';"))
  55. RPostgreSQL::dbGetQuery(con, stringr::str_c("create database ", admin, ";"))
  56. print(stringr::str_c(admin, " postgresql account created with password: ", pass))
  57. # Reset the root account password
  58. RPostgreSQL::dbGetQuery(con, stringr::str_c("alter user postgres password '", pass, "';"))
  59. print(stringr::str_c("Changed password for user postgres to: ", pass))
  60. # Disconnect the db
  61. RPostgreSQL::dbDisconnect(con)
  62. pass
  63. }
  64. #' Manage services
  65. #'
  66. #' Start/stop/restart services
  67. #'
  68. #' @param service The service to manage (pg for short for postgresql-9.1)
  69. #' @param action The action to perform
  70. #' @param use_sudo Use sudo if not executed by root account (defaults to T)
  71. #' @export
  72. service <- function(service, action = c("start", "stop", "restart"), use_sudo = T)
  73. {
  74. service <- ifelse(service == "pg", "postgresql-9.1", service)
  75. cmd <- ifelse(use_sudo, "sudo service", "service")
  76. system(stringr::str_c(cmd, service, action, sep = " "))
  77. }