Skip to content

Commit

Permalink
add systemd timers and services for import and downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Dec 5, 2016
1 parent e44910f commit 47f1a98
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 28 deletions.
8 changes: 4 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ AllCops:
DisplayCopNames: true
Exclude:
- Rakefile
- db/**/*
- bin/**/*
- config/**/*
- db/**/*
- dist/**/*
- lib/tasks/**/*
- bin/**/*
- test/**/*
- vendor/**/*
- tmp/**/*
- build/**/*
- vendor/**/*

Rails:
Enabled: true
Expand Down
2 changes: 1 addition & 1 deletion app/services/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.run
mappings.each { |b| Importer.new(b).run }
Recording::Cleaner.new.run
rescue Exception => e
Rails.logger.error("FATAL: #{e}")
Rails.logger.error("FATAL: #{e}\n #{e.backtrace.join("\n ")}")
ExceptionNotifier.notify_exception(e)
end

Expand Down
3 changes: 2 additions & 1 deletion app/services/import/recording/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def imported
end

def import_directories
Rails.application.secrets.import_directories
Rails.application.secrets.import_directories ||
raise('IMPORT_DIRECTORIES not set!')
end

private
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ production:
secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
archive_home: <%= ENV['ARCHIVE_HOME'] %>
import_directories:
<% ENV['IMPORT_DIRECTORIES'].to_s.strip.split(',') do |d| %>
<% ENV['IMPORT_DIRECTORIES'].to_s.strip.split(',').each do |d| %>
- <%= d.strip %>
<% end %>
days_to_keep_imported: <%= ENV['DAYS_TO_KEEP_IMPORTED'] || 1 %>
Expand Down
11 changes: 11 additions & 0 deletions config/systemd/raar-downgrade.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# /etc/systemd/system/raar-downgrade.service

[Unit]
Description=Raar audio archive downgrade

[Service]
Type=simple
User=raar
Environment="RAAR_LOG=stdout"
EnvironmentFile=/var/www/raar/.env
ExecStart=/usr/bin/scl enable rh-ruby22 -- /var/www/raar/current/bin/downgrade
12 changes: 12 additions & 0 deletions config/systemd/raar-downgrade.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# /etc/systemd/system/raar-downgrade.timer
# sudo systemctl enable raar-downgrade.timer
# sudo systemctl start raar-downgrade.timer

[Unit]
Description=Raar audio archive downgrade

[Timer]
OnCalendar=03:15

[Install]
WantedBy=timers.target
11 changes: 11 additions & 0 deletions config/systemd/raar-import.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# /etc/systemd/system/raar-import.service

[Unit]
Description=Raar audio archive import

[Service]
Type=simple
User=raar
Environment="RAAR_LOG=stdout"
EnvironmentFile=/var/www/raar/.env
ExecStart=/usr/bin/scl enable rh-ruby22 -- /var/www/raar/current/bin/import
12 changes: 12 additions & 0 deletions config/systemd/raar-import.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# /etc/systemd/system/raar-import.timer
# sudo systemctl enable raar-import.timer
# sudo systemctl start raar-import.timer

[Unit]
Description=Raar audio archive import

[Timer]
OnCalendar=*:05,20,35,50

[Install]
WantedBy=timers.target
72 changes: 51 additions & 21 deletions doc/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The system configuration is done with environment variables that must be availab

The following environment variables may be used to configure RAAR. They are all read into the application in `config/secrets.yml`, except for the database settings in `config/database.yml`.

An easy way to manage these values is to create a `~/.env` file with several `VAR=value` assignments in the home directory of the system user the application is running as. The assignments then may easily be loaded from `.bashrc` (`export $(cat .env | xargs)`) or as environment files (e.g. by systemd).

### Common

| Name | Description | Default |
Expand Down Expand Up @@ -67,6 +69,15 @@ The import and downgrade executables live in `bin/import` and `bin/downgrade`, r

The cron jobs should run as the application user in its home directory (`$RAAR_HOME`). It is essential that the environment variables defined above are available to the processes.

## Systemd Timers

As an alternative to cron jobs, the import and downgrade executables may also be run as Systemd timers. Copy the files from `config/systemd/*` to `/etc/systemd/system/`, make adjustments matching your deployment environment and run the following commands as root to start the timers:

systemctl enable raar-import.timer
systemctl enable raar-downgrade.timer
systemctl start raar-import.timer
systemctl start raar-downgrade.timer

## Free IPA

In order for the authentication to work with username and password, Free IPA may be configured to capture `POST` requests to `v1/login`. The form parameters `username` and `password` are provided. The application expects `REMOTE_USER`, `REMOTE_USER_GROUPS`, `REMOTE_USER_FIRST_NAME`, `REMOTE_USER_LAST_NAME` or `EXTERNAL_AUTH_ERROR` headers to be set. If the `REMOTE_USER` is set, a user object with the generated API token is returned.
Expand All @@ -87,39 +98,58 @@ Perform the following steps on a CentOS or the corresponding ones on a different
* Add `/opt/rh/rh-ruby22/root/usr/local/bin` to PATH in `/opt/rh/rh-ruby22/enable`
* `gem install bundler --no-ri --no-rdoc`
* Install Passenger according to these [instructions](https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/apache/oss/el7/install_passenger.html).
* Create `/var/www/raar/.bashrc` with all environment variables required for configuration.
* Create `/var/www/raar/.env` with all environment variables required for configuration.
* Create `/var/www/raar/.bashrc` with the following content:

alias rails='bundle exec rails'

source /opt/rh/rh-ruby22/enable

export $(cat .env | xargs)

* Create `/var/www/raar/.bash_profile` containing `source ~/.bashrc`.
* Create `/etc/httpd/conf.d/raar_env.inc` with `SetEnv` statements with the same values as before.
* Create `/etc/httpd/conf.d/raar.conf` with the following contents:
* Create `/etc/httpd/conf.d/raar.conf` with the following content:

<VirtualHost *:80>

ServerName raar
ServerAlias archiv.rabe.ch

<VirtualHost *:80>
DocumentRoot /var/www/raar-ui

ServerName raar
ServerAlias archiv.rabe.ch
Alias /api /var/www/raar/current/public
<Location /api>
PassengerBaseURI /api
PassengerAppRoot /var/www/raar/current
PassengerRuby /opt/rh/rh-ruby22/root/usr/bin/ruby
PassengerMinInstances 2
</Location>

DocumentRoot /var/www/raar-ui
<Directory "/var/www/raar/current/public/">
AllowOverride None
Allow from all
Options -MultiViews
</Directory>

Alias /api /var/www/raar/current/public
<Location /api>
PassengerBaseURI /api
PassengerAppRoot /var/www/raar/current
PassengerRuby /opt/rh/rh-ruby22/root/usr/bin/ruby
PassengerMinInstances 2
</Location>
Include conf.d/raar_env.inc

<Directory "/var/www/raar/current/public/">
AllowOverride None
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

Include conf.d/raar_env.inc
* Restart Apache: `systemctl restart httpd`.
* Deploy the application to `/var/www/raar/current` as described below.
* Copy all files from `config/systemd` to `/etc/systemd/system`.
* Enable and start Systemd timers for the import and downgrade services:

</VirtualHost>
systemctl enable raar-import.timer
systemctl enable raar-downgrade.timer
systemctl start raar-import.timer
systemctl start raar-downgrade.timer

* View logs with `journalctl -u "raar-*" -f`.

### Developer-side

* Copy `config/deploy/production.example.rb` to `config/deploy/production.rb` and add your server.
* Add the raar user created above as well.
* Add the `raar` user created above as well.
* Run `cap production deploy`

0 comments on commit 47f1a98

Please sign in to comment.