-
Notifications
You must be signed in to change notification settings - Fork 0
Add boot hooks doc #1
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
title: Add Custom Boot Hook to /mnt/jrc-comms/hooks/boot.d | ||
--- | ||
|
||
This guide explains how to add a custom boot hook to `/mnt/jrc-comms/hooks/boot.d/` in applications that execute scripts in numerical order. Follow these steps to ensure proper execution order and functionality. | ||
|
||
!!! Assumption: | ||
We assume you have root access to modify files in `/mnt/jrc-comms/hooks/boot.d/`. | ||
!!! | ||
|
||
## Create Custom Boot Hook | ||
|
||
### 1. Create Your Script | ||
Create a new shell script with a filename starting with `99-` (to ensure it runs last). For example: | ||
|
||
```bash | ||
#!/bin/bash | ||
/mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
|
||
echo "Running custom boot task..." | ||
``` | ||
|
||
### 2. Set Permissions and Ownership | ||
Make the script executable and ensure it’s owned by `root`: | ||
|
||
```bash | ||
sudo chown root:root /mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
sudo chmod +x /mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
``` | ||
|
||
### 3. Verify Execution Order | ||
The application runs scripts in ascending order based on their numeric prefixes. Scripts added to `/mnt/jrc-comms/hooks/boot.d` will be injected into `/opt/jrc/hooks/boot.d` based on script prefix automatically. For example: | ||
|
||
- `05-mount-recovery-mount` runs first (found in `/opt/jrc/hooks/boot.d`) | ||
- `10-cluster-clean` runs next (found in `/opt/jrc/hooks/boot.d`) | ||
- `99-custom-task` runs last (added to `/mnt/jrc-comms/hooks/boot.d`) | ||
|
||
**Key rules:** | ||
- Prefixes determine execution order (e.g., `00-` to `99-`) | ||
- Use two-digit numbering for clarity (e.g., `05-`, `10-`, `99-`) | ||
- Scripts with the same prefix may execute in lexicographical order, but avoid ambiguity by using unique prefixes | ||
- Scripts added to `/mnt/jrc-comms/hooks/boot.d` will persist AMI upgrades, stack clones, etc. | ||
|
||
--- | ||
|
||
## Example Walkthrough | ||
To log system time at the end of the boot process: | ||
|
||
```bash | ||
#!/bin/bash | ||
/mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
|
||
LOGFILE="/var/log/custom-boot.log" | ||
echo "Boot completed at: $(date)" >> $LOGFILE | ||
``` | ||
|
||
--- | ||
|
||
## Troubleshooting Tips | ||
1. **Test your script manually** before relying on the boot process: | ||
|
||
```bash | ||
sudo /mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
``` | ||
|
||
2. **Check logs** for errors (e.g., `/var/log/syslog` or `journalctl`) | ||
|
||
3. **Validate script syntax** using: | ||
|
||
```bash | ||
bash -n /mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
``` | ||
|
||
By following this structure, you can extend the boot process with custom logic while maintaining predictable execution order. | ||
|
||
--- | ||
|
||
### Alternative to fstab Mounting Using Boot Hook Script | ||
|
||
AutoPilot's boot hook system provides a more reliable alternative to `/etc/fstab` for bind mounts within dynamic environments, particularly when dealing with paths that might not be available during early boot stages. | ||
|
||
The following is an example of how you would implement a boot hook script to create hard links. Typically this would be accomplished within `/etc/fstab`. | ||
|
||
## Boot Hook Script Implementation | ||
|
||
### 1. Create /mnt/jrc-comms/hooks/boot.d/99-links Script | ||
|
||
Creates bind mounts after filesystems are available | ||
|
||
```bash | ||
#!/bin/bash | ||
/mnt/jrc-comms/hooks/boot.d/99-links | ||
|
||
echo "Creating bind mounts..." | ||
mount --bind /var/www/domain.com/shared/var/salesexport /home/user/salesexport | ||
mount --bind /var/www/domain.com/shared/media/importexport /home/user/importexport | ||
``` | ||
|
||
### 2. Set Permissions | ||
|
||
```bash | ||
sudo chmod +x /mnt/jrc-comms/hooks/boot.d/99-links | ||
sudo chown root:root /mnt/jrc-comms/hooks/boot.d/99-links | ||
``` | ||
|
||
## Verification | ||
1. **Validate script syntax**: | ||
|
||
```bash | ||
bash -n /mnt/jrc-comms/hooks/boot.d/99-custom-task | ||
``` | ||
|
||
2. **Check active mounts**: | ||
|
||
```bash | ||
mount | grep bind | ||
``` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must also be executable or it's ignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated!