Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include capistrano tasks that reload the services after deploying. #12642

Merged
merged 1 commit into from
May 10, 2020

Conversation

berkes
Copy link
Contributor

@berkes berkes commented Dec 17, 2019

After a successfull deploy, I need the services to switch over to use the
new code. I need to (re)start the services. Also, often, I need to inspect whether the services are running or why they crashed.

The capistrano tasks in this PR do that.

I'm not certain whether this is useful to mastodon at all.

  1. It requires the server to be set up using these services AND
  2. Requires the "deploy" user to be allowed to run those commands with passwordless sudo.

Please let me know what you think about this PR. Is it useful to Mastodon? Would it be useful if I make some changes? Or should it simply be closed?

It might be more appropriate in the specific environment-deploy files for example: config/deploy/production.rb. Otherwise, I probably need to add documentation (but where?) and a PR in the ansible-repo to set this up properly.

On my server, using ansible, I configure the deploy user to be allowed to restart services. Without such a configuration, the deploy will fail with this setup.

- name: "Allow deploy-user to reload the services"
  lineinfile:
    dest: /etc/sudoers
    state: present
    line: "%{{ deploy_user }} ALL=NOPASSWD: /bin/systemctl reload {{ item }}.service"
    validate: 'visudo -cf %s'
  with_items:
    - mastodon-web
    - mastodon-streaming
    - mastodon-sidekiq

- name: "Allow deploy-user to check the service"
  lineinfile:
    dest: /etc/sudoers
    state: present
    line: "%{{  deploy_user }} ALL=NOPASSWD: /bin/systemctl status {{ item }}.service"
    validate: 'visudo -cf %s'
  with_items:
    - mastodon-web
    - mastodon-streaming
    - mastodon-sidekiq

EDIT: additional detail, is that it depends on the service and its setup whether it can be reloaded. I have set up my units on my server such that they can be reloaded but with the service-examples in /dist of this repo, for example, Sidekiq cannot be reloaded, only restarted.

@berkes
Copy link
Contributor Author

berkes commented Dec 17, 2019

These tasks are added to capistrano:
Schermafdruk van 2019-12-17 12-05-45

@Gargron
Copy link
Member

Gargron commented Jan 11, 2020

I have set up my units on my server such that they can be reloaded but with the service-examples in /dist of this repo, for example, Sidekiq cannot be reloaded, only restarted.

Can you submit those? Although I'm not sure reloading Sidekiq makes a difference since it's not user-facing and is not accepting connections. Curious how you got the streaming server to reload.

@berkes
Copy link
Contributor Author

berkes commented Jan 13, 2020

Can you submit those? Although I'm not sure reloading Sidekiq makes a difference since it's not user-facing and is not accepting connections. Curious how you got the streaming server to reload.

Certainly!

Do you want them in a PR, fully integrated, or do you want them for reference, attached? Because in order to make them a full PR, I'll have to rewrite their structure and logic from my setup to that for mastodon.

Although I'm not sure reloading Sidekiq makes a difference since it's not user-facing

Well, Sidekiq is using the codebase, database structure and so on, so you'll want to reload after a new deploy. E.g. to get new mail-templates, locales or to use migrated models.

@Gargron
Copy link
Member

Gargron commented Jan 14, 2020

Although I'm not sure reloading Sidekiq makes a difference since it's not user-facing

Well, Sidekiq is using the codebase, database structure and so on, so you'll want to reload after a new deploy. E.g. to get new mail-templates, locales or to use migrated models.

Sorry, you misunderstood. I'm talking about reload specifically, which is usually done through a SIGHUP and meant to restart a program without completely stopping and then starting it. Puma for example supports reload for zero-downtime code changes, i.e. it continues processing and accepting requests while it is loading new code.

config/deploy.rb Outdated
end

after 'deploy:publishing', 'systemd:web:reload'
after 'deploy:publishing', 'systemd:sidekiq:reload'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, only web has a reload. The others need a restart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

I've changed and refactored the code.

Rebased and force pushed too.

After a successfull deploy, I need the services to switch over to use the
new code. I need to restart the services.

These capistrano tasks do that.
@berkes berkes force-pushed the feature/reload-after-cap-deploy branch from 6a4f787 to 2b3f967 Compare March 10, 2020 19:33
@Gargron Gargron merged commit e09e225 into mastodon:master May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants