Hi all,
this is meant as a quick note for other geniuses like me who tend to forget stopping/starting Flarum-related services like the redis queue or realtime when updating/installing/removing extensions in the forum.
As I've forgotten this several times into past, also running into weird issues sometimes, I've now finally automated this. Hopefully it helps some other lazy geniuses out there too. Also, it clears caches and re-creates assets.
Basically it's quite simple and consists out of two parts:
- Adjusting
composer.json
to add some scripts/hooks to be run during update
- Adjusting
/etc/sudoers
to allow a non-privileged user to restart relevant services, also without an interactive passsword prompt
Steps:
1. Step, the composer.json
file. Add following at the bottom:
"scripts": {
"pre-update-cmd": [
"sudo /bin/systemctl stop flarum-queue",
"sudo /bin/systemctl stop flarum-realtime"
],
"post-update-cmd": [
"sudo /bin/systemctl start flarum-queue",
"sudo /bin/systemctl start flarum-realtime",
"php7.4 flarum recache:clear",
"php7.4 flarum cache:clear",
"php7.4 flarum cache:assets --css --js --locales"
]
},
(Pro-Tipp: Watch out for correct brackets and commas! Adjust commands based on your setup.)
2. Step, the /etc/sudoers
file. Add/adjust as following (run visudo
):
# Cmnd alias specification
Cmnd_Alias FLARUM_QUEUE = /bin/systemctl stop flarum-queue, /bin/systemctl start flarum-queue, /bin/systemctl restart flarum-queue
Cmnd_Alias FLARUM_REALTIME = /bin/systemctl stop flarum-realtime, /bin/systemctl start flarum-realtime, /bin/systemctl restart flarum-realtime
# User privilege specification
flarumuser ALL=NOPASSWD: FLARUM_QUEUE
flarumuser ALL=NOPASSWD: FLARUM_REALTIME
On the next update, it should look like:
$ sudo -u flarumuser composer require blomstra/realtime:"*@dev"
./composer.json has been updated
Running composer update blomstra/realtime
> sudo /bin/systemctl stop flarum-queue
> sudo /bin/systemctl stop flarum-realtime
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
- Upgrading blomstra/realtime (0.1-beta.31 => 0.2-beta.8)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
- Downloading blomstra/realtime (0.2-beta.8)
- Upgrading blomstra/realtime (0.1-beta.31 => 0.2-beta.8): Extracting archive
Generating autoload files
135 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> sudo /bin/systemctl start flarum-queue
> sudo /bin/systemctl start flarum-realtime
> php7.4 flarum recache:clear
ReCache cleared!
> php7.4 flarum cache:clear
Clearing the cache...
> php7.4 flarum cache:assets --css --js --locales
Caching assets ...
Caching forum js file
Caching forum css file
Caching forum dark css file
Caching forum en css & js files
Caching admin js file
Caching admin css file
Caching admin dark css file
Caching admin en css & js files
Happy updating.