Class: SmartMachine::Grids::Nextcloud
- Defined in:
- lib/smart_machine/grids/nextcloud.rb
Instance Method Summary collapse
- #downer ⇒ Object
-
#initialize(name:) ⇒ Nextcloud
constructor
A new instance of Nextcloud.
- #uper ⇒ Object
Methods inherited from Base
#machine_has_engine_installed?, #platform_on_machine?, #user_bash
Methods included from Logger
configure_logger_for, included, #logger, logger_for
Constructor Details
#initialize(name:) ⇒ Nextcloud
Returns a new instance of Nextcloud.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smart_machine/grids/nextcloud.rb', line 4 def initialize(name:) config = SmartMachine.config.grids.nextcloud.dig(name.to_sym) raise "nextcloud config for #{name} not found." unless config @image = config.dig(:image) @host = config.dig(:host) @admin_user = config.dig(:admin_user) @admin_password = config.dig(:admin_password) @mysql_host = config.dig(:mysql_host) @mysql_port = config.dig(:mysql_port) @mysql_user = config.dig(:mysql_user) @mysql_password = config.dig(:mysql_password) @mysql_database_name = config.dig(:mysql_database_name) @redis_host = config.dig(:redis_host) @redis_port = config.dig(:redis_port) @redis_password = config.dig(:redis_password) @name = name.to_s @home_dir = File.('~') end |
Instance Method Details
#downer ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/smart_machine/grids/nextcloud.rb', line 76 def downer # Disconnecting networks system("docker network disconnect nginx-network #{@name}") system("docker network disconnect #{@mysql_host}-network #{@name}") # Stopping & Removing containers - in reverse order print "-----> Stopping container #{@name} ... " if system("docker stop '#{@name}'", out: File::NULL) puts "done" print "-----> Removing container #{@name} ... " if system("docker rm '#{@name}'", out: File::NULL) puts "done" end end end |
#uper ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/smart_machine/grids/nextcloud.rb', line 25 def uper FileUtils.mkdir_p("#{@home_dir}/machine/grids/nextcloud/#{@name}/html") # Creating & Starting containers print "-----> Creating container #{@name} ... " command = [ "docker create", "--name='#{@name}'", "--env VIRTUAL_HOST=#{@host}", "--env LETSENCRYPT_HOST=#{@host}", "--env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email}", "--env LETSENCRYPT_TEST=false", "--env NEXTCLOUD_TRUSTED_DOMAINS=#{@host}", "--env NEXTCLOUD_ADMIN_USER=#{@admin_user}", "--env NEXTCLOUD_ADMIN_PASSWORD=#{@admin_password}", "--env MYSQL_HOST=#{@mysql_host}:#{@mysql_port}", "--env MYSQL_USER=#{@mysql_user}", "--env MYSQL_PASSWORD=#{@mysql_password}", "--env MYSQL_DATABASE=#{@mysql_database_name}", "--env REDIS_HOST=#{@redis_host}", "--env REDIS_HOST_PORT=#{@redis_port}", "--env REDIS_HOST_PASSWORD=#{@redis_password}", "--user `id -u`:`id -g`", "--sysctl net.ipv4.ip_unprivileged_port_start=0", "--volume='#{@home_dir}/smartmachine/grids/nextcloud/#{@name}/html:/var/www/html'", "--restart='always'", "--network='nginx-network'", "#{@image}" ] if system(command.compact.join(" "), out: File::NULL) system("docker network connect #{@mysql_host}-network #{@name}") system("docker network connect #{@redis_host}-network #{@name}") # This is needed to set the correct file permissions for redis-session.ini file inside the container. FileUtils.touch("#{@home_dir}/machine/grids/nextcloud/#{@name}/redis-session.ini") system("docker cp #{@home_dir}/machine/grids/nextcloud/#{@name}/redis-session.ini #{@name}:/usr/local/etc/php/conf.d/redis-session.ini") FileUtils.rm("#{@home_dir}/machine/grids/nextcloud/#{@name}/redis-session.ini") puts "done" puts "-----> Starting container #{@name} ... " if system("docker start #{@name}", out: File::NULL) puts "done" else raise "Error: Could not start the created #{@name} container" end else raise "Error: Could not create #{@name} container" end end |