## Setup of Schema Webstack container and WSL host for local development # # C.Campbell 12.07.2023 # # Definitions: localhost: the WSL host used for development # conatiner: the LXD container that provides the directus, mysql and express service for developement # nginx: the reverse proxy on the WSL host # redis: the redis service on the WSL host # # In production, the stack is setup exactly as it is on a WSL host, except that it can be any # debian based Linux server, any Linux/BSD server can be used but the apt commands will be replaced # with whatever is native to that system # # if it is not yet configured, we need to setup the nginx reverses proxy on localhost # note if you already have apache2 or another web server installed, those will need to stop # before nginx can run on port 80 # # install nginx current from nginx stable sudo aptitude install curl gnupg2 ca-certificates lsb-release ubuntu-keyring cd ~ curl https://nginx.org/keys/nginx_signing.key -o nginx_signing.key gpg --dearmor nginx_signing.key sudo cp nginx_signing.key.gpg /etc/apt/trusted.gpg.d/nginx_signing.key.gpg sudo vim /etc/apt/sources.list.d/nginx.list ## add following if ubuntu 22, aka jammy deb https://nginx.org/packages/ubuntu/ jammy nginx deb-src https://nginx.org/packages/ubuntu/ jammy nginx sudo aptitude update sudo aptitude show nginx # should show at least nginx 1.24+ # sudo vim /etc/nginx/conf.d/dev.localhost.conf # add the following upstream dev_upstream { zone upstreams 64K; server 127.0.0.1:9001 max_fails=1 fail_timeout=6s; keepalive 2; } server { listen [::]:80; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name dev.localhost; location = /favicon.ico { return 301 https://dhcbzpsju3qeg.cloudfront.net/img/favicon.ico; } location = /robots.txt { alias /var/www/html/robots.txt; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://dev_upstream; proxy_redirect off; proxy_read_timeout 10s; } } # reload or restart nginx sudo systemctl reload nginx # or sudo systemctl restart nginx ## the next steps will need a working snap environment # its likely the proxy will be in your way so do the following # only required on dev localhost sudo snap set system proxy.http="http://172.16.0.129:3128" sudo snap set system proxy.https="http://172.16.0.129:3128" # now try to install the most current LXD sudo snap install lxd --channel=latest/stable # if lxd is already installed but at a lower version than 5.x, the following sudo snap refresh lxd --channel=latest/stable # go through with the defaults of the init script, unless the defaults are obviously wrong lxd init # make the NAT prerouting connections needed to map the host to container sudo ufw allow in on lxdbr0 comment 'lxdbr0 for LXD' sudo ufw route allow in on lxdbr0 comment 'lxdbr0 for LXD' sudo ufw route allow out on lxdbr0 comment 'lxdbr0 for LXD' # allow normal services, there could be more depending on the resposibilities of the instance sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw enable # set proxy for lxc commands # only required on dev localhost lxc config set core.proxy_http http://172.16.0.129:3128 lxc config set core.proxy_https http://172.16.0.129:3128 ## the host also needs redis # there are many ways to install redis, but to get the latest/stable the easiest way is snap # this part I will need to see on someones system that does not have it installed # we have the configuration files to control the snap with systemctl and configure it properly # sudo snap install redis # create the service override to set authentication sudo mkdir /etc/systemd/system/snap.redis.server.service.d sudo touch /etc/systemd/system/snap.redis.server.service.d/override.conf sudo vim /etc/systemd/system/snap.redis.server.service.d/override.conf # add the following and then after the requirepass flag put a string for the auth, a strong password no special characters [Service] ExecStart= ExecStart=/usr/bin/snap run redis.server --requirepass # example from ohio-web [Service] ExecStart= ExecStart=/usr/bin/snap run redis.server --requirepass 804309921d514c7a sudo systemctl daemon-reload # start and check the redis service sudo systemctl start snap.redis.server.service sudo systemctl status snap.redis.server.service # this was required for whatever reason, the override did not get picked up on the first start command sudo systemctl restart snap.redis.server.service sudo systemctl status snap.redis.server.service ## we need LXD of course, if that is not installed follow these steps # Create a new LXD project space lxc project create cosequin.com --config features.images=false --config features.profiles=false # switch to new project lxc project switch cosequin.com # import best version of a stack container as a starting point lxc import ~/LXD_containers/denamarin.com_12062023.tar.xz stack --project cosequin.com # remove the previous device configs from the previous instance image # example lxc config device remove stack localdev lxc config device remove stack node9001 lxc config device remove stack denamarin_live lxc config device remove stack denamarin_stage lxc config device remove stack directus8055 lxc config device remove stack directus8155 lxc config device remove stack directus8255 # start the stack and check the assigned ip address lxc start stack lxc list # the IP address is 10.80.77.161, this is needed to add the device proxy config(s) # first add the disk mount for the development repo, this is only for localhost development # enter the stack container as the webstack user, create the dev mount point lxc exec stack -- su - webstack # now if everything is working correctly we are in the stack container as webstack user mkdir -p cosequin.com/dev/stack # go ahead and make the dev directus as well mkdir -p cosequin.com/dev/directus cp -r denamarin.com/stage/directus/* cosequin.com/dev/directus/ cp denamarin.com/stage/directus/.env cosequin.com/dev/directus/ # modify the directus .env to whatever you want for local developement # stop all running pm2 processes pm2 stop all # exit out of the webstack user and enter the stack as root to create the new dev database exit lxc exec stack -- su - mysql create database cosequin_dev; grant all on cosequin_dev.* to 'developer_user'; quit # exit the root user and go back in as the webstack user to restore a database snapshot to the new database exit lxc exec stack -- su - webstack cd snapshot/ # unzip the database snapshot and add USE cosequin_dev; to the top somewhere gzip -d snapshot.stage.12052023.sql.gz # zip the database and restore it gzip snapshot.stage.12052023.sql ./restore-snapshot.sh cosequin_dev snapshot.stage.12052023.sql.gz # modify pm2 ~/etc/ecosystem.config.js to start the new directus instance module.exports = { apps : [{ name: 'Directus Dev', cwd: '/home/webstack/cosequin.com/dev/directus', script: 'npx directus start', } ] }; # remove the old pm2 processes pm2 del all # start pm2 with the new config file pm2 start ~/etc/ecosystem.config.js # now the new dev directus instance should me running # hop out of the container back to localhost and create the device proxy for dev directus exit lxc config device add stack directus_dev proxy listen=tcp:127.0.0.1:8055 connect=tcp:10.80.77.161:8055 # at this point the dev directus is here: http://localhost:8055/admin # if things look good, time to finish the stack # go to the directory chosen for the stack repository # example cd ~/node.js/cosequin-sw git status # should be showing origin/dev dev branch # if there is no node_modules present npm install # now create a disk config to mount this repo into the container at the path: cosequin.com/dev/stack # we are doing this because it is the easiest way to develop on localhost and instantly apply to the # container, example lxc config device add stack dev_repo disk source=/home/ccampbell/node.js/cosequin-sw/ path=/home/webstack/cosequin.com/dev/stack/ # now we can check the container config, example lxc config show stack # should show these devices: devices: dev_repo: path: /home/webstack/cosequin.com/dev/stack/ source: /home/ccampbell/node.js/cosequin-sw/ type: disk directus_dev: connect: tcp:10.80.77.161:8055 listen: tcp:127.0.0.1:8055 type: proxy root: path: / pool: default type: disk # now we can enter the stack and check that the dev repo is mounted lxc exec stack -- su - webstack ls -alt cosequin.com/dev/stack/ # should show something like this, where before it was empty total 88 drwxr-xr-x 8 nobody nogroup 4096 Dec 7 18:10 .git drwxr-xr-x 98 nobody nogroup 4096 Dec 7 18:10 node_modules drwxr-xr-x 9 nobody nogroup 4096 Dec 7 18:10 . -rw-r--r-- 1 nobody nogroup 40572 Dec 7 18:10 package-lock.json drwxrwxr-x 1 webstack webstack 26 Dec 7 16:41 .. -rw-r--r-- 1 nobody nogroup 517 Dec 7 16:08 .env -rw-r--r-- 1 nobody nogroup 2585 Dec 7 15:55 index.js -rw-r--r-- 1 nobody nogroup 864 Dec 7 15:55 package.json drwxr-xr-x 2 nobody nogroup 4096 Dec 7 15:55 services drwxr-xr-x 2 nobody nogroup 4096 Dec 7 15:54 routes drwxr-xr-x 2 nobody nogroup 4096 Dec 7 15:54 views drwxr-xr-x 2 nobody nogroup 4096 Dec 7 15:54 etc drwxr-xr-x 2 nobody nogroup 4096 Dec 7 15:54 tmp -rw-r--r-- 1 nobody nogroup 89 Dec 7 15:54 .gitignore # now exit out of the stack and we will create the device proxy for the stack # example, choose a different port if needed exit lxc config device add stack stack_dev proxy listen=tcp:127.0.0.1:9001 connect=tcp:10.80.77.161:9001 # show the container config again lxc config show stack # should see something like this now, example devices: dev_repo: path: /home/webstack/cosequin.com/dev/stack/ source: /home/ccampbell/node.js/cosequin-sw/ type: disk directus_dev: connect: tcp:10.80.77.161:8055 listen: tcp:127.0.0.1:8055 type: proxy root: path: / pool: default type: disk stack_dev: connect: tcp:10.80.77.161:9001 listen: tcp:127.0.0.1:9001 type: proxy # enter the stack container again and set up pm2 config for the stack lxc exec stack -- su - webstack vim ~/etc/ecosystem.config.js # should look something like this: notice the addition of the watch attributes # this makes it so pm2 will autoreload when code changes module.exports = { apps : [{ name: 'Directus Dev', cwd: '/home/webstack/cosequin.com/dev/directus', script: 'npx directus start', }, { name: 'Stack Dev', cwd: '/home/webstack/cosequin.com/dev/stack', script: 'node index.js', env: {"NODE_ENV":"development","PORT":9001}, watch: ['/home/webstack/cosequin.com/dev/stack'], ignore_watch: ['node_modules'] } ] }; # restart pm2 pm2 start ~/etc/ecosystem.config.js exit # connect another service to locahost, this is for the apollo/server web interface lxc config device add stack apollo_dev proxy listen=tcp:127.0.0.1:4000 connect=tcp:10.80.77.161:4000 # mount the localhost dev repo for apollo into the container, keeping in mind this is only for development lxc config device add stack apollo disk source=/home/ccampbell/node.js/apollo-server/ path=/home/webstack/cosequin.com/dev/apollo/ # Devices used on ccampbell localhost for stack container devices: apollo: path: /home/webstack/cosequin.com/dev/apollo/ source: /home/ccampbell/node.js/apollo-server/ type: disk apollo_dev: connect: tcp:10.80.77.161:4000 listen: tcp:127.0.0.1:4000 type: proxy dev_repo: path: /home/webstack/cosequin.com/dev/stack/ source: /home/ccampbell/node.js/cosequin-sw/ type: disk directus_dev: connect: tcp:10.80.77.161:8055 listen: tcp:127.0.0.1:8055 type: proxy root: path: / pool: default type: disk stack_dev: connect: tcp:10.80.77.161:9001 listen: tcp:127.0.0.1:9001 type: proxy # remove host development disk mounts lxc config device remove stack apollo; \ lxc config device remove stack dev_repo; # remove host config for container export lxc config device remove stack apollo_dev; \ lxc config device remove stack directus_dev; \ lxc config device remove stack stack_dev; \ lxc config show stack; # export container lxc export stack LXD_containers/webstack_gold_v2.tar.xz --optimized-storage # rebuild host config lxc config device add stack dev_repo disk source=/home/ccampbell/node.js/cosequin-sw/ path=/home/webstack/cosequin.com/dev/stack/; \ lxc config device add stack apollo_repo disk source=/home/ccampbell/node.js/apollo-server/ path=/home/webstack/cosequin.com/dev/apollo/; \ lxc config device add stack apollo_dev proxy listen=tcp:127.0.0.1:4000 connect=tcp:10.80.77.161:4000; \ lxc config device add stack stack_dev proxy listen=tcp:127.0.0.1:9001 connect=tcp:10.80.77.161:9001; \ lxc config device add stack directus_dev proxy listen=tcp:127.0.0.1:8055 connect=tcp:10.80.77.161:8055; \ lxc config show stack; # ohio-web current denamarin stage deployment devices: directus8056: connect: tcp:10.80.77.243:8055 listen: tcp:127.0.0.1:8056 type: proxy localdev: path: /home/webstack/schema-webstack/ source: /home/ccampbell/node.js/schema-webstack/ type: disk node9002: connect: tcp:10.80.77.243:9001 listen: tcp:127.0.0.1:9002 type: proxy # ohio-web cosequin.com stack deployment config lxc config device add stack stack_dev proxy listen=tcp:127.0.0.1:9005 connect=tcp:10.134.132.161:9003; \ lxc config device add stack directus_dev proxy listen=tcp:127.0.0.1:8060 connect=tcp:10.134.132.161:8055; # stack redis on ohio-web IO_REDIS_HOST="10.134.132.1" # directus config on ohio-web REDIS_HOST="10.134.132.1" PUBLIC_URL="https://ohio-api.nutramax.com/cosequin/dev" # ohio-web denamarin.com stage/live configuration lxc config device add stage directus_live proxy listen=tcp:127.0.0.1:8153 connect=tcp:10.134.132.161:8153; \ lxc config device add stage stack_live proxy listen=tcp:127.0.0.1:9003 connect=tcp:10.134.132.161:9003; \ # www.denamarin.com DNS A 3.16.115.109 AAAA 2600:1f16:984:ff00:7c07:13d2:af5d:2b73 # route 53 name servers for denamarin.com ns-1825.awsdns-36.co.uk. ns-674.awsdns-20.net. ns-110.awsdns-13.com. ns-1086.awsdns-07.org. Changing the IP of an instance: By default the containers are using "dhcp" to configure the IP address, but this is not working since the containers always pull the same IP address. Do the following to set a static bridge IP lxc exec stack -- su - vim /etc/netplan/10-lxc.yaml # configure the static IP, the yaml should be something like this: network: version: 2 ethernets: eth0: dhcp4: false addresses: - 10.134.132.163/24 routes: - to: 0.0.0.0/0 via: 10.134.132.1 # save and exit then run netplan apply # now exit out of the container and stop/start restart the container lxc restart stack # rebuild /etc/resolv.conf lxc exec stack -- su - rm /etc/resolv.conf touch /etc/resolv.conf vim /etc/resolv.conf # contents of etc/resovl.conf nameserver 1.1.1.1 nameserver 8.8.8.8 search . # reconfigure the devices devices: directus_dev: connect: tcp:10.134.132.161:8055 listen: tcp:127.0.0.1:8060 type: proxy root: path: / pool: pool0 type: disk stack_dev: connect: tcp:10.134.132.161:9003 listen: tcp:127.0.0.1:9005 type: proxy lxc config device remove stack directus_dev; \ lxc config device remove stack stack_dev; \ # ohio-web cosequin.com stack deployment config lxc config device add stack stack_dev proxy listen=tcp:127.0.0.1:9005 connect=tcp:10.134.132.163:9003; \ lxc config device add stack directus_dev proxy listen=tcp:127.0.0.1:8060 connect=tcp:10.134.132.163:8055; # solliquin project space lxc project create solliquin.com --config features.images=false --config features.profiles=false # Configure the container to control resource usage on the host machine # these commands use cosequin.com, stack as the project, container however this can be used # for any container lxc stop stack --project cosequin.com # edit the container config lxc config edit stack --project cosequin.com # under the config: section add the following # the cpu.allowance should be adjusted to a value that makes sense for the production environment limits.cpu.allowance: 50% limits.memory: 512MB limits.memory.enforce: soft # now we can configure mysql to stay as lean as possible # enter the container as root lxc exec stack --project cosequin.com -- su - vim /etc/mysql/mysql.conf.d/mysqld.cnf # add the following at the bottom of the config file, make sure these are not already defined # tweaking mysqld for container use innodb_buffer_pool_size = 8M innodb_buffer_pool_instances = 1 innodb_buffer_pool_chunk_size = 8M innodb_read_io_threads = 2 innodb_write_io_threads = 2 innodb_compression_level = 3 innodb_fsync_threshold = 16384 innodb_io_capacity = 100 innodb_lock_wait_timeout = 10 innodb_log_file_size = 4M innodb_thread_concurrency = 4 temptable_max_ram = 8M # attempting to connect to mysql via unix socket # the following did not end up working for the webstack container user, and was # abandoned for using TCP to the bridge the same way as Redis # however this is a good learning experience and with enough time # could be achieved # lxc config device remove stack mysql_unix # set up a socket bind out to the host mysql socket lxc config device add stack mysql_unix proxy bind=instance connect=unix:/var/run/mysqld/mysqld.sock listen=unix:/var/tmp/mysqld.sock # authentication by default on socket is only allowed for root, enable auth_socket and create a normal socket user # in mysqld.cnf add plugin-load-add=auth_socket.so # create a new socket user, user has to match with the user running the cli CREATE USER 'ccampbell'@'localhost' IDENTIFIED WITH auth_socket; grant developer_user to 'ccampbell'@'localhost'; # or if the developer_user role is not created grant all on cosequin_dev.* to 'ccampbell'@'localhost'; CREATE USER 'webstack'@'localhost' IDENTIFIED WITH auth_socket; grant all on cosequin_dev.* to 'webstack'@'localhost'; CREATE USER '1001001'@'localhost' IDENTIFIED WITH auth_socket; grant all on cosequin_dev.* to '1001001'@'localhost'; CREATE USER '1000000'@'localhost' IDENTIFIED WITH auth_socket; grant all on cosequin_dev.* to '1000000'@'localhost'; # test with this command, should not error mysql -h localhost --user ccampbell -S /var/run/mysqld/mysqld.sock -D cosequin_dev # was able to use sockets for the root user, but not for the non-priv webstack user # falling back to creating a normal tcp path for mysql out to the host # this does not work because mysql is already bound, this will have to work the same as redis # lxc config device add stack mysql_proxy proxy listen=tcp:127.0.0.1:3306 connect=tcp:10.80.77.161:3306; CREATE USER 'webdev'@'10.80.77.1' identified by 'RwEUHq@5eXmO!ppY'; grant all on cosequin_dev.* to 'webdev'@'10.80.77.1'; # have to do this because directus does not support mysql2 connector yet, mysql 8 uses stronger auth plugin by default ALTER USER 'webdev'@'10.80.77.1' identified with mysql_native_password by 'RwEUHq@5eXmO!ppY'; ALTER USER 'webdev'@'127.0.0.1' identified with mysql_native_password by 'RwEUHq@5eXmO!ppY'; # the above would not work as intended so it was abandoned, left for learning purposes # directus still reporting issues with auth plugin, trying this as mentioned as solve # ATTENTION, this is the configuration that will play nicely with directus # that uses the old original mysql connector package # CREATE USER 'webdev'@'%' identified with mysql_native_password by 'RwEUHq@5eXmO!ppY'; grant all on cosequin_dev.* to 'webdev'@'%'; # C. Campbell 04.08.2024 # deploying cosequin.com project instance on us-east-1 # most of the installation steps above were followed without issues, and where there were updates needed # it was revised. Here we are up to the point where the cosequin.com lxc project was created # on us-east-1 here is the following status: lxd and redis have been installed by snap "latest" versions apache is already running on http/https so it will be used ProxyPass to the container mysqld 8 already existed and needs to be configured for container(s) to use lxc network list +--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+ | NAME | TYPE | MANAGED | IPV4 | IPV6 | DESCRIPTION | USED BY | STATE | +--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+ | eth0 | physical | NO | | | | 0 | | +--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+ | lxdbr0 | bridge | YES | 10.182.204.1/24 | fd42:ce44:43c8:e602::1/64 | | 1 | CREATED | +--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+ lxc storage list +---------+--------+--------------------------------------------+-------------+---------+---------+ | NAME | DRIVER | SOURCE | DESCRIPTION | USED BY | STATE | +---------+--------+--------------------------------------------+-------------+---------+---------+ | default | btrfs | /var/snap/lxd/common/lxd/disks/default.img | | 1 | CREATED | +---------+--------+--------------------------------------------+-------------+---------+---------+ # note the bridge is running on 10.182.204.1 so this will need to be reconfigured in the container, # it may be worth it at this point to learn how to set the IP for the bridge, to match dev localhost # so things wont have to be reconfigured # here we can change the auto issued ipv4 of the bridge to match dev localhost lxc network edit lxdbr0 # request the latest cosequin_dev database dump to us-east-1 for mysql import mkdir ~/lxd cd ~/lxd aws s3 cp s3://cosequin.com/LXD/cosequin_dev.04042024_1.sql.gz . # look at the current mysql on us-east-1, make sure we do not have any naming database instance conflicts sudo mysql show databases; +--------------------+ | Database | +--------------------+ | cosequin_2021 | | dasuquin_2021 | | dasuquin_stage | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.01 sec) # Looks like we are good to call our database the expected cosequin_dev # set up the new database called cosequin_dev create database cosequin_dev; CREATE USER 'webdev'@'%' identified with mysql_native_password by 'RwEUHq@5eXmO!ppY'; grant all on cosequin_dev.* to 'webdev'@'%'; # leave the mysql console exit # gunzip the database file so we can set the USE cosequin_dev; needed for import, we also need to create the # mysql database and user and grant the correct privileges, we do that next # we are in ~/lxd gzip -d cosequin_dev.04042024_1.sql.gz vim cosequin_dev.04042024_1.sql # realized at this point we will need to do some cleanup on the dev localhost database instance and then do a full # mysql dump, not ignoring any tables. # jumping off of us-east-1 and back to dev localhost mysql where the database lives ATM # created a full backup of the cosequin_dev from dev localhost with the directus_activity deleted, this took the # database backup down to around 100k # jumping back on us-east-1, pull down the full backup, gunzip it and add use cosequin_dev; then # import the cosequin_dev database sudo mysql < cosequin_dev_full.04082024.sql # now we have the database installed so we can bring over the container and set up a ProxyPass for the directus # we will create a new subdomain for the directus dev,stage,live called datalayer.cosequin.com # jump into CrapDaddy and create a new subdomain pointed at us-east-1 # Added A record for datalayer pointing to 52.202.6.227 dig datalayer.cosequin.com ;; ANSWER SECTION: datalayer.cosequin.com. 600 IN A 52.202.6.227 # now we can go and set up Apache on us-east-1 to handle datalayer.cosequin.com # first start with a stub virtualhost on 80 for running certbot Created in /etc/apache2/sites-available$ sudo vim datalayer.cosequin.com.conf ServerName datalayer.cosequin.com DocumentRoot /var/www/html # create link into sites-enabled sudo a2ensite datalayer.cosequin.com.conf # check config sudo apachectl configtest sudo systemctl reload apache2 sudo certbot -d datalayer.cosequin.com --apache # this will create and enable this file /etc/apache2/sites-available/datalayer.cosequin.com-le-ssl.conf # add the following to block all sources aside from the internal network # this will also be used for dev.cosequin.com Order deny,allow Deny from all Allow from 208.104.82.162 # at this point jump out of us-east-1 and configure the cosequin container for export lxc exec stack --project cosequin.com -- su - # lets configure netplan so it will use the proper IP address instead of dhcp auto vim /etc/netplan/10-lxc.yaml network: version: 2 ethernets: eth0: dhcp4: false addresses: - 10.80.77.161/24 routes: - to: 0.0.0.0/0 via: 10.80.77.1 # set /etc/resolv.conf nameserver 8.8.8.8 nameserver 1.1.1.1 search . # now lets disable the pm2 services while we export and remove the mounted dev devices lxc exec stack --project cosequin.com -- su - webstack pm2 status pm2 delete all pm2 save # disable the services we will not use for this deployment, we will use mysql on the production host lxc exec stack --project cosequin.com -- su - systemctl disable pm2-webstack.service systemctl disable mysql.service systemctl stop mysql # should show almost nothing running systemctl status # jump out of the container and restart it to make sure pm2 does not restart lxc restart stack --project cosequin.com # the above should make sure pm2 does not auto start the node services at boot or restart, # this is useful for the export/import # remove the dev device mounts lxc config device remove stack apollo --project cosequin.com lxc config device remove stack apollo_dev --project cosequin.com lxc config device remove stack dev_repo --project cosequin.com # set autoboot to false, we have had issues with this in the past. once the config is "OK" we can set it back to true lxc config edit stack --project cosequin.com # at this point we can attempt an export lxc stop stack --project cosequin.com lxc export stack ~/LXD_containers/cosequin.com_us-east-1.tar.xz --optimized-storage --project cosequin.com # push export up to private s3 bucket for retrieval aws s3 cp cosequin.com_us-east-1.tar.xz s3://cosequin.com/LXD/cosequin.com_us-east-1.tar.xz # jump back into us-east-1 and pull down the container export ssh us-east-1 cd ~/lxd aws s3 cp s3://cosequin.com/LXD/cosequin.com_us-east-1.tar.xz . lxc import cosequin.com_us-east-1.tar.xz stack --project cosequin.com lxc exec stack --project cosequin.com -- su - webstack # attempted to start just the directus node service with current settings, # this failed because the mysql on the host is only running on 127.0.0.1 # exit out of the container and modify the mysqld config to run on 0.0.0.0 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # change bind address bind-address = 0.0.0.0 sudo systemctl restart mysql.service lxc exec stack --project cosequin.com -- su - webstack pm2 start ~/etc/ecosystem.conf.js # or pm2 start 1 pm2 log 1 # now should report no issues, if there are errors pm2 stop 1 # exit out of the container and lets attempt to set up the proxy for https://datalayer.cosequin.com/dev/ to point to http://127.0.0.1:8055/dev/ sudo vim /etc/apache2/sites-available/datalayer.cosequin.com-le-ssl.conf sudo a2enmod proxy_http # final setup of the datalayer virtualhost file # there are other ways to do this but this works so far Order deny,allow Deny from all Allow from 208.104.82.162 ProxyPreserveHost On ProxyPass "http://127.0.0.1:8055/" ProxyPassReverse "http://127.0.0.1:8055/" # make sure this did not make any difference to the running services on the host # on us-east-1 this did not cause any issues # the other existing devices we can leave because us-east-1 does not have any # services that will collide with 9001 or 8055 # went to ohio-web and removed the dev.cosequin.com entries from the nginx config(s) directus and stack # we will also be switching dev.cosequin.com to point to this machine # modify the existing A record A record for dev pointing to 52.202.6.227 # created file for dev.cosequin.com.conf for certbot cd /etc/apache2/sites-available sudo a2ensite dev.cosequin.com.conf sudo apachectl configtest sudo systemctl reload apache2.service # make sure DNS has flipped dig dev.cosequin.com dev.cosequin.com. 300 IN A 52.202.6.227 # create cert sudo certbot -d dev.cosequin.com --apache # modify the dev.cosequin.com file to proxy to container sudo vim dev.cosequin.com-le-ssl.conf Order deny,allow Deny from all Allow from 208.104.82.162 ProxyPreserveHost On ProxyPass "http://127.0.0.1:9001/" ProxyPassReverse "http://127.0.0.1:9001/" sudo systemctl reload apache2.service # enter the container lxc exec stack --project cosequin.com -- su - webstack # change apollo .env to point out to the host mysql vim cosequin.com/dev/apollo/server/src/.env Change host to DB_HOST=10.80.77.1 # modify the etc/ecosystem file, add apollo back to the apps array vim ~/etc/ecosystem.config.js # should look something like this now module.exports = { apps : [{ name: 'Cosequin Directus Dev', cwd: '/home/webstack/cosequin.com/dev/directus', script: 'npx directus start', }, { name: 'Cosequin Dev Apollo', cwd: '/home/webstack/cosequin.com/dev/apollo/server/src', script: 'node index.js', env: {"NODE_ENV":"development","NODE_DEBUG":"APOLLO"} } ] }; pm2 start etc/ecosystem.config.js pm2 log 2 # there might be missing dependencies or an issue, if so cd ~/cosequin.com/dev/apollo npm install pm2 restart 2 # now make sure the stack is up to date cd ~/cosequin.com/dev/cosequin-sw git status git fetch git pull origin dev vim .env # set the VHOST_PATTERN=dev.cosequin.com # now modify the pm2 ecosystem file again, should look like this now module.exports = { apps : [{ name: 'Cosequin Directus Dev', cwd: '/home/webstack/cosequin.com/dev/directus', script: 'npx directus start', }, { name: 'Cosequin Dev Stack', cwd: '/home/webstack/cosequin.com/dev/cosequin-sw', script: 'node index.js', env: {"NODE_ENV":"development","PORT":9001} }, { name: 'Cosequin Dev Apollo', cwd: '/home/webstack/cosequin.com/dev/apollo/server/src', script: 'node index.js', env: {"NODE_ENV":"development","NODE_DEBUG":"APOLLO"} } ] }; # hop out of the container and hop back in as root, re-enable the pm2.webstack service lxc exec stack --project cosequin.com -- su - systemctl enable pm2-webstack.service lxc config device add stack directus_live proxy listen=tcp:127.0.0.1:8056 connect=tcp:10.80.77.161:8056 lxc config device add stack stack_live proxy listen=tcp:127.0.0.1:9002 connect=tcp:10.80.77.161:9002 # solliquin live setup lxc config device add stack directus_live proxy listen=tcp:127.0.0.1:8157 connect=tcp:10.134.132.164:8157 --project solliquin.com lxc config device add stack stack_live proxy listen=tcp:127.0.0.1:9008 connect=tcp:10.134.132.164:9008 --project solliquin.com sudo certbot -d www.solliquin.com,solliquin.com --nginx