9

I need to update source files (pull and update from the repository) in my production server, run migrations, and regenerate cached assets.

Is there any mechanism in Symfony 2 to do this safely? Like putting the site into 'maintainance mode' (which should throw a 503) or something?

HappyDeveloper
  • 12,480
  • 22
  • 82
  • 117

5 Answers5

5

I've just found a Bundle for Symfony 2, which offers you 2 extra-commands in the console to put your application into maintenance mode. Here you go: https://github.com/lexik/LexikMaintenanceBundle

Davincho
  • 300
  • 2
  • 8
  • 1
    The LexikMaintenanceBundle, while is good, requires Symfony to work. CorleyMaintenanceBundle in my opinion is better, since it works on Apache/Nginx level. – TheFrost May 24 '16 at 20:21
3

I've been trying to decide how I would implement this. On one hand, Symfony2 provides decent prod caching, so if you're not destructively modifying your database schema (removing columns or tables, etc), you can probably get away with just changing the schema, deploying from your repo, then clearing your prod cache. That's how I handle things most of the time.

On the other hand, if you DO want to go into maintenance mode, you'll want a solution that has minimal load on the framework (ie, you probably don't want to fire up the kernel), or you're defeating the purpose anyway: taking the load off the framework while you muck with things.

If it were me, I'd probably write a simple maintenance script that just sets a 503 header, maybe serves up some static html (pregenerated from my site templates) and sends it back to the user, then use some conditional logic in my app.php to use that when I should be in maintenance mode. It's ugly, but it works.

Problematic
  • 17,567
  • 10
  • 73
  • 85
  • Is it really that involved? You can't just add a wildcard route based off a config option? – Mike B Nov 12 '11 at 13:14
  • The only problem with that is that it requires loading the framework. If your changes won't break things while you're updating, that's really the way to go. Otherwise, a manual script is probably the best bet. – Problematic Nov 12 '11 at 16:03
  • I replace the app.php file with a maintenance.php file I created. as soon as deploy is finished app.php is put back. – tmas Aug 05 '16 at 14:26
1

I can recommend using deployer (http://deployer.org/) to deploy your Symfony2 application. This way you dont need a maintenance page. The tool ships with a symfony2 and symfony3 template already included. It generates your assets, warms up the cache and keeps track of your release directories. It's easy to roll back to a previous release also. there is a "current"-symlink which always points to your current release directory. If a release deployment is complete this link updates to the newly created release directory.

Regarding doctrine migrations you need to write a custom task for that.

Atan
  • 1,095
  • 2
  • 12
  • 17
1

Not sure how to go about this for a bigger site where a user could be in the middle of some kind of transaction (shopping for instance) but for a smaller site could you not just use a .htaccess file (the one in the web directory assuming that is your root) to redirect to some maintenance page instead of into app.php.

Kasheen
  • 5,401
  • 2
  • 31
  • 41
0

Please look at capifony http://capifony.org/

It has excellent support for Symfony2.

Pablo
  • 17
  • 1