Install postgresql in FreeBSD jail enable sysvipc

Installen postgresql on a FreeBSD jail can result in an error when intializing the database.

 service postgresql initdb
running bootstrap script ... 2023-02-24 10:21:41.757 CET [29388] FATAL:  could not create shared memory segment: Function not implemented
2023-02-24 10:21:41.757 CET [29388] DETAIL:  Failed system call was shmget(key=37383, size=56, 03600).

By default shared memory via sysvipc is not allowed.

sysctl security.jail.sysvipc_allowed
#=> security.jail.sysvipc_allowed: 0

To solve this enable sysvipc for the given jail...
For bastille this can be added to the config file: /usr/local/bastille/jails/jailname/jail.conf

allow.sysvipc = 1;

Restart jail.

sysctl security.jail.sysvipc_allowed
#=> security.jail.sysvipc_allowed: 1

Rails ActiveStorage import on Mac OS X, missing files

Capistrano-db-tasks is a nice tool to pull production data to the local environment. This nicely imports all SQL data and imports the activestorage files from the /storage folders to the development environment.

When importing the active storage files, not all blob-files are imported. So you get missing file on your local machine. Which is not very desirable, certainly when you are working on a rails upgrade and want to test if everything is working.

I'm using a MacOS X development machine. By default OS X uses a case insensitive filesystem (APFS).

The production machine uses FreeBSD or Linux as OS. Which has a case sensitive filesystem.

ActiveStorage generate case sensitive filenames by default (Why!?!). So you can have a folder 'xE' and 'Xe', which are 2 different folders on BSD/Linux, but not on my Mac.

Today I configured a solution suggested by Brian Boyko: https://brianboyko.medium.com/a-case-sensitive-src-folder-for-mac-programmers-176cc82a3830

Mounting a case-sensitive container. '/Volumes/casesensitive'

Via disutility you can create a case-sensitive APFS container. This container shares the space of you main disk. But is case-sensitive.

I use this container to link my storage folders. (I don't have the need to have a case sensitive code directory) .
This is extra nice, because the gigantic storage files aren't stored in my projects folder anymore.

ln -s /Volumes/casesensitive/project/storage ~/project/storage

Airbrake / errbit error reporting not working with puma 6 / rails 7

(Note issue below has been resolve, see link below for best resolution)

Last few weeks I busy updating several of my Ruby on Rails apps to Ruby 3.2.0 and Rails 7.0. (running Puma 6)
Because upgrading an app requires me to monitor the apps, and get notified when something happens, it's crucial that my error notification tool works.
I use airbrake with errbit as backend.

Most apps report perfectly after upgrade. But I notice one of my Apps didn't report any errors.

This app used the preload! functionality of puma.
With the preload option:

  • rake airbrake:test just works.
  • Exception from sidekiq Jobs are reported,
  • but controller exceptions aren't working

Removing the preload! of puma solve the issue.


But this isn't always possible, in one of my apps, I use the embedded puma variant. In this article Mike describes the steps how to do this.

This method requires a preload. (so removing it isn' a good solution)

After a lot of debugging/testing I found a simple workaround to solves the non-reporting issue. Forcing a syncronized notify instead of the default async.
I noticed the async config option was removed from airbrake, so I don't know how to disable it. For now I use the flexibility of Ruby to change the default notify implementation to the synchronized variant.

## force to airbrake to be NOT async, to solve issues with preload! puma
def Airbrake.notify(...)
  Airbrake.notify_sync(...)
end

With this included in my airbrake initializer the errors are noticed again :-)

NOTE
I've created a PR for ruby/timeout to fix this issue https://github.com/ruby/timeout/pull/25

Which has been merged in the v0.3.2 release of the Timeout gem. 🎉
https://github.com/ruby/timeout/releases/tag/v0.3.2

Rails mysql structure.sql dump contains AUTO_INCREMENT

When rails generates a structure.sql dump for MySQL it contains the AUTO_INCREMENT value. Which is anoying because this is not something you want to happen.

CREATE TABLE `active_storage_variant_records` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `blob_id` bigint NOT NULL,
  `variation_digest` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index_active_storage_variant_records_uniqueness` (`blob_id`,`variation_digest`),
  CONSTRAINT `fk_rails_993965df05` FOREIGN KEY (`blob_id`) REFERENCES `active_storage_blobs` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=471 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Look at the part: AUTO_INCREMENT=471

After digging through the activerecord code, I saw I could sneak in a mysqldump option for the dump call. Yeah! 👍🏻

But there isn't such option 😕. It's an ancient BUG/Feature of mysql, which of course still isn't resolved in MySQL 8. https://bugs.mysql.com/bug.php?id=20786

Why would you like to dump the table structure (without data) with the AUTO_INCREMENT value!?

As a workaround it's possible to enhance the db:schema:dump task in a custom rake file (lib/tasks/remove_autoincrement_from_dump.rake).
So the AUTO_INCREMENT part is removed from it.

Rake::Task['db:schema:dump'].enhance do
  structure_sql_path = Rails.root.join("db/structure.sql")
  if File.exist?(structure_sql_path)
    sql = File.read(structure_sql_path)
    File.write(structure_sql_path, sql.gsub(/AUTO_INCREMENT=[0-9]+/, ""))
  end
end

References: