Commit Graph

21 Commits

Author SHA1 Message Date
Hannah Wolfe
60ab97cf03 Fixed Ghost hiding config errors behind a crash
refs: https://github.com/TryGhost/Team/issues/558

- we can't use our logging lib to log a config error, because logging requires config to work
- we have to use console, as there's nothing else available at this point
- we can't even use notify to tell CLI a bad thing happened here, because that also requires config and logging
- there is no precedent or ref material for the code 999
   - it's just meant to be a clearly different code to -1/1/2/3 we've used elsewhere
   - it signifies that things went so wrong we weren't even able to handle the error gracefully with logging
2021-03-18 16:32:51 +00:00
Hannah Wolfe
c7b843471f Added limit service
refs: https://github.com/TryGhost/Team/issues/510

- added and wired up the new limit service, which is a lazy-loaded service
- this handles the case that there are host limits set in config, and wraps all the logic needed for detecting exceeded limits & throwing limit errors
- expects limits to be set in config under `host_settings.limits`
- supported limits are managed in the limit service, outside of core
2021-03-03 13:43:05 +00:00
Naz
476d4389c6 Bumped scheduler to use v4 API
refs https://github.com/TryGhost/Team/issues/513

- The bump does not effect scheduled post as URL with authentication token is generated during runtime for DefaultScheduler.
- This needs to be checked for SchedulerAdapter implementations which use persistant storage
2021-03-03 18:45:41 +13:00
Naz
7f51cbf4e9 Fixed typo Migratior -> Migration 2021-02-24 13:05:29 +13:00
Hannah Wolfe
089655c2e2 Cleaned up boot require order, debugs & inlined mount
- Continuing cleanup and clarification of the boot process
- By locating requires and inits more closely together its easier to see what happens where and to get timings
- Improved consistency of the debug begin/end statements
- Added "Step" comments to the main process
- Inlined the mountGhost function, for readability and consistency with the other steps
2021-02-23 14:28:43 +00:00
Hannah Wolfe
3373b5bbd1 Cleaned up use of express in ghost-server
- There is now one true way to start Ghost - you create a server, and then call start with an express app
- We may well expand this again to improve testing pathways in future, but it will be done with a bit more clarity about expectations
2021-02-23 12:33:00 +00:00
Hannah Wolfe
3c7e2e3ac2 Cleaned up requires in boot error handling
- moved logging variable outside of the try-catch block, so it doesn't need a 2nd require
- I was considering having config,logging etc shared components required in a function together, but it's less readable
- Having a try-catch for loading shared components before main boot is also confusing
- This is simplest and most readable IMO
2021-02-23 12:27:27 +00:00
Hannah Wolfe
70ed998838 Replaced db.ready event with direct call to urlservice
refs dd715b33dc

- this is the last event that is used to trigger part of the standard boot process
- events make the code harder to read/reason about
- the urlservice is one of the most core and critical components in Ghost, possibly the biggest consumer of time and memory
- we want to have the work it is doing front and center so that we can improve it
2021-02-23 10:05:59 +00:00
Hannah Wolfe
dd715b33dc Replaced themes.ready event with direct call
refs b1a98b0b67

- note: I already replaced server.start with themes.ready in the above commit
- events make the code harder to read/reason about
- long term it would be nice to have a concept of hooks for services, but for now explicit is clearer
2021-02-22 21:05:06 +00:00
Hannah Wolfe
176433e307 Refactored notify to send started + ready
- In the old boot the server wasn't started til we were ready
- In new boot, we start the server immediately and send the old started event
- Then, when we are ready to accept some traffic, we send a ready event
- At the moment, ready isn't quite sent at the right time:
   - It _should_ be when we're ready to serve real traffic, not just send 503s
   - This is after the URL generation has finished
   - But this requires more refactoring work :(
   - So for now we send when everything else is ready
- This really needs some tests
2021-02-19 20:42:10 +00:00
Hannah Wolfe
2527efd6fc Moved notify out of GhostServer
- make this a standalone module
2021-02-19 20:22:56 +00:00
Hannah Wolfe
b65cb7bd7b Renamed announceServerReadiness to notifyServerStarted
- Notify is a more familiar name e.g. systemd has the sd_notify system which this is similar to
- We're actually announcing the server started, it's not actually ready for traffic (will serve 503s)
2021-02-19 20:11:35 +00:00
Hannah Wolfe
d150516ec3 Improved readability of ghost server and boot
- removed some unused code I added preivously
- refactored boot logging into a mini class for readability
2021-02-19 15:04:55 +00:00
Hannah Wolfe
481e2425af Finalised new boot process
- This commit removes the old boot process and any files that are no longer needed as a result
- Remove the duplicate event for triggering inactive themes to load
- Tidied up a few other bits
2021-02-19 13:15:12 +00:00
Hannah Wolfe
b28b4e1cb0 Cleaned up, commented + co-located new boot
- moved the DB init back into the boot file so everything is colocated - want it to be EASY to reason about whats happening
- added some more debug, and made the method signatures all the same
- expanded on comments to make it clear what the intentions are here, as there's a lot more work to do
2021-02-19 12:27:49 +00:00
Hannah Wolfe
71521d166e Readded job scheduling to boot process
- This was missing from the new boot process!
- Added it back because obviously it is necessary :D
2021-02-19 10:09:41 +00:00
Hannah Wolfe
4b472615a8 Added Sentry to new boot process
- With the new boot finalised it's clearer to see where this needs to go
- Update comments to add more clarity around what's happening and why
- Cleaned up the version require, as this was prep for maybe using version via config, which won't work in MigratorConfig
2021-02-19 09:20:41 +00:00
Hannah Wolfe
f1be3418d9 Switched tests to use new boot method
- We currently have 2 boot systems in the codebase, until now the tests were still running against the old one
- Regression tests using the forceStart + subdir flag no longer work. These need reworking, but this _should_ be easier later
- Note those tests work fine if they were the first tests run, it is only the case of trying to restart the server with a subdirectory after starting without that doesn't work
2021-02-18 20:24:49 +00:00
Hannah Wolfe
21bea79848 Fixed inactive themes not loading [WIP]
- Currently the new boot process breaks the loading of inactive themes because the theme loader event isn't wired until after the server.start event is fired
- This is a WIP fix, there needs to be some bigger refactoring of the boot process once the old process is gone
2021-02-15 17:19:21 +00:00
Daniel Lockyer
1a370a3708
Fixed path to analytics-events in boot file
refs 0b79abf5b2

- in the referenced commit, we refactored the boot code to simplify it
- one of the required files was not updated with the change, so the path
  was wrong
- this wouldn't have been easily visible from local testing because it's
  based upon a config flag that isn't on by default
- this commit updates the path to the file
2021-02-09 12:51:06 +00:00
Hannah Wolfe
0b79abf5b2 Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces

This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
   - Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-08 11:56:44 +00:00