From fc9bdc613c8a9e6f7d5f31a2f17530cdd599fa19 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Thu, 25 Jul 2024 12:14:27 -0500 Subject: [PATCH] Updates to get things working for new system --- .gitignore | 5 ++ README.md | 133 +++++++++++++++++++------------ data/db_2024_02_15.sql | 2 +- data/updates/0001_new_schema.sql | 2 +- startup.sh => startup.sh.sample | 0 unicorn.rb => unicorn.rb.sample | 0 unicorn.service.sample | 11 +++ 7 files changed, 101 insertions(+), 52 deletions(-) rename startup.sh => startup.sh.sample (100%) rename unicorn.rb => unicorn.rb.sample (100%) create mode 100644 unicorn.service.sample diff --git a/.gitignore b/.gitignore index 3920185d..bf774dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,11 @@ /db/scripts/private/ .idea +## Service start up configs +.config +unicorn.rb +startup.sh + ## Documentation cache and generated files: /.yardoc/ /_yardoc/ diff --git a/README.md b/README.md index 56508484..b9fd218d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,18 @@ +# UNL Reservations -Installation -============ +UNL reservation system for schedule resources, classes, etc. + +## Quick Tutorial + +1. Service spaces refer to different silos of the University that will utilize resources. E.g. the math department, the Honors program, or University Communication. +2. Super Admins of a space can do anything, including giving others access and privileges to the space. +3. Resources are created, and then may be reserved by anyone who has the User Access privilege in the space. +4. Events *may* include a resource reservation but do not have to. +5. Admins with the right privilege can set the *hours* of the space, which indicate when reservations can be made. +6. The agenda is a quick overview of the day for Admins to look at. + +## Installation Local -Using local resources ---------------------- 0. Run `xcode-select --install`. Congratulations, you have saved yourself 5000 insanity points. 1. Get the right ruby on your machine. UNL Resource Scheduler currently runs on Ruby 2.6.5. Get RVM on your machine with `\curl -sSL https://get.rvm.io | bash`. 2. Now using RVM, install the ruby with `rvm install 2.6.5`. @@ -11,69 +20,93 @@ Using local resources 4. In the project root, install the gems using `bundle install`. 5. Create a mysql database you'd like to use, you can typically use one on your computer. `brew install mysql` if necessary. 6. `config/config.json` is a committed file, and a template for the configuration. Create a copy in the same directoy named `server.json` and edit it to match your database. You will also need to include your site keys for google reCaptcha which can be generated at https://www.google.com/recaptcha/ for the V2 checkbox. -7. Your database is currently blank. Import the production database or copy https://git.unl.edu/iim/unl-resource-scheduler/tree/master/db/migrate into this project and run the migrations from the root of the project using `rake migrate` to bring in all the tables and columns. +7. Your database is currently blank. Run any sql queries in `./data` to install database and the updates to it. 8. Install the WDN Framework into the `public/wdn` directory...see [WDN Documentation](http://wdn.unl.edu/documentation). 9. Start the server by going to the root directory and doing `bundle exec shotgun -o 0.0.0.0 -p 9393`. This launches the server on localhost port 9393, listening everywhere (you can use your iimlemburg.unl.edu or whichever), and the server will automatically update to new code. If you add gems to the bundle, you will need to re-execute this command. 10. Navigate to `localhost:9393/` or similar and begin! 11. In another terminal, type `bundle exec guard` in the project root to execute LESS compilation. -Quick Tutorial -============== -1. Service spaces refer to different silos of the University that will utilize resources. E.g. the math department, the Honors program, or University Communication. -2. Super Admins of a space can do anything, including giving others access and privileges to the space. -3. Resources are created, and then may be reserved by anyone who has the User Access privilege in the space. -4. Events *may* include a resource reservation but do not have to. -5. Admins with the right privilege can set the *hours* of the space, which indicate when reservations can be made. -6. The agenda is a quick overview of the day for Admins to look at. +## Installation on server + +1. Run `sudo -u {user} -s` run commands as a user and navigate to your project's root +2. Run `cp ./config/config.json ./config/server.json` to copy config file and customize it to your environment +3. Run `ln -s {path to WDN Templates} {path to project root}/public/wdn` to symlink WDN Templates to your project +4. Run `/bin/bundler install` to install dependencies +5. Install database schema running files in `./data` +6. You will need to get a service running for unicorn using systemd + 1. Run `cp ./startup.sh.sample ./startup.sh` and customize file for your domain and sock + 2. Run `cp ./unicorn.rb.sample ./unicorn.rb` and customize file for your domain and sock + 3. Run `mkdir -p ~/.config/systemd/user` to set up systemd user directory + 4. Run `cp ./unicorn.service.sample ~/.config/systemd/user/unicorn.service` and customize file for your domain and sock +7. Run `systemctl --user start unicorn` to start the service +8. Run `systemctl --user enable unicorn` to start the service on boot + +## Deploying Updates on Staging -Deploying Updates on Staging -=============================== 1. Run these commands to restart the unicorn server. -``` -cat innovationstudio-manager-test.pid -sudo -u innovationstudio-test kill -9 [replace with PID from first command] -sudo -u innovationstudio-test ./startup.sh -``` + + ``` bash + cat innovationstudio-manager-test.pid + sudo -u innovationstudio-test kill -9 [replace with PID from first command] + sudo -u innovationstudio-test ./startup.sh + ``` + 2. After restarting the unicorn server make sure that there are only two scheduler processes running. The scheduler processes handle sending out automated emails on a daily basis. There should be one for the staging environment and one for the production environment. If more than 2 processes are running then users will receive duplicate emails. Run the command below to check if multiple processes are running. You should only get 2 process IDs back. -``` -pgrep ruby -``` + + ``` bash + pgrep ruby + ``` + 3. If you get more than 2 processes IDs then you need to check which users started each process. There should be one process started by the innovationstudio-test user(the staging user) and one process started by the innovationstudio user. You can check the user of a process with this command where pid is the process ID. -``` -ps -o user= -p pid -``` + + ``` bash + ps -o user= -p pid + ``` + 4. Once you determine which processes are extra (if any) then kill them with this command. -``` -sudo -u innovationstudio kill -9 pid -``` -Deploying Updates on Production -=============================== + ``` bash + sudo -u innovationstudio kill -9 pid + ``` + +## Deploying Updates on Production + 1. Run these commands to restart the unicorn server. -``` -sudo -u innovationstudio -s -H -systemctl --user restart unicorn -``` + + ``` bash + sudo -u innovationstudio -s -H + systemctl --user restart unicorn + ``` + 2. If the production environment fails to start after executing those commands then an error must have occurred. You can view the error log with the following command. This command will print the last 50 lines of the error log: -``` -cat error.log | tail -n 50 -``` + + ``` bash + cat error.log | tail -n 50 + ``` + 3. If the error log happens to say that the unicorn server cannot start because the process already exists (even though the server is still down) you can run the following commands to determine the process ID and to kill the processe. After killing the existing process and trying to restart the server you should get a more helpful error message in the error log if the server still fails to start. -Use this command to find the process ID. The process you're looking for should have this in the command column: ```unicorn master -l /run/httpd-local/innovationstudio.sock -E production -c /var/www/html/innovationstudio-manager.unl.edu/unicorn.rb```. -``` -ps aux -``` -Use this command to kill the process ID -``` -sudo -u innovationstudio kill -9 pid -``` +Use this command to find the process ID. The process you're looking for should have this in the command column: -CRON -==== -``` + ``` bash + unicorn master -l /run/httpd-local/innovationstudio.sock -E production -c /var/www/html/innovationstudio-manager.unl.edu/unicorn.rb + ``` + + ``` bash + ps aux + ``` + + Use this command to kill the process ID + + ``` bash + sudo -u innovationstudio kill -9 pid + ``` + +## CRON + +``` text 0 12 * * * ruby ././scripts/email_expiring_users.rb 0 12 * * * ruby ././scripts/email_unconfirmed_trainers.rb 0 22 * * * ruby ././scripts/email_expiring_users_vehicle_update.rb #@reboot /var/www/html/innovationstudio-manager.unl.edu/startup.sh -``` \ No newline at end of file +``` diff --git a/data/db_2024_02_15.sql b/data/db_2024_02_15.sql index 19b74af2..227e613f 100644 --- a/data/db_2024_02_15.sql +++ b/data/db_2024_02_15.sql @@ -240,7 +240,7 @@ INSERT INTO `event_types` (`id`, `description`, `service_space_id`) VALUES (7, 'RSVP Only Event', 1), (8, 'Tour', 1), (9, 'Conference', 4), -(10, 'Scheduling', 1); +(10, 'Scheduling', 1), (11, 'HRC Training', 1); -- -------------------------------------------------------- diff --git a/data/updates/0001_new_schema.sql b/data/updates/0001_new_schema.sql index f6f56d83..be8bb258 100644 --- a/data/updates/0001_new_schema.sql +++ b/data/updates/0001_new_schema.sql @@ -564,7 +564,7 @@ CREATE TABLE IF NOT EXISTS `reservation`.`emergency_contacts` ( `secondary_phone_number` VARCHAR(45) NULL, PRIMARY KEY (`id`)); ---Update user's table to include primary and secondary contact ids. +--Update users table to include primary and secondary contact ids. ALTER TABLE `reservation`.`users` ADD COLUMN `primary_emergency_contact_id` INT(11) NULL DEFAULT NULL AFTER `date_of_birth`, ADD COLUMN `secondary_emergency_contact_id` INT(11) NULL DEFAULT NULL AFTER `primary_emergency_contact_id`, diff --git a/startup.sh b/startup.sh.sample similarity index 100% rename from startup.sh rename to startup.sh.sample diff --git a/unicorn.rb b/unicorn.rb.sample similarity index 100% rename from unicorn.rb rename to unicorn.rb.sample diff --git a/unicorn.service.sample b/unicorn.service.sample new file mode 100644 index 00000000..5bda7d90 --- /dev/null +++ b/unicorn.service.sample @@ -0,0 +1,11 @@ +[Unit] +Description=Unicorn + +[Service] +Environment=GEM_PATH=/var/www/html/innovationstudio-manager.unl.edu/gems:$GEM_PATH +WorkingDirectory=/var/www/html/innovationstudio-manager.unl.edu +ExecStart=/bin/bundle exec unicorn -l /run/httpd-local/innovationstudio.sock -E production -c /var/www/html/innovationstudio-manager.unl.edu/unicorn.rb +Restart=always + +[Install] +WantedBy=default.target \ No newline at end of file