Skip to content

Commit 4f50b67

Browse files
authored
Merge pull request #1 from jetrails/boot-hooks
Add boot hooks doc
2 parents 35cf640 + f904058 commit 4f50b67

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: Add Custom Boot Hook to /mnt/jrc-comms/hooks/boot.d
3+
---
4+
5+
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.
6+
7+
!!! Assumption:
8+
We assume you have root access to modify files in `/mnt/jrc-comms/hooks/boot.d/`.
9+
!!!
10+
11+
## Create Custom Boot Hook
12+
13+
### 1. Create Your Script
14+
Create a new shell script with a filename starting with `99-` (to ensure it runs last). For example:
15+
16+
```bash
17+
#!/bin/bash
18+
/mnt/jrc-comms/hooks/boot.d/99-custom-task
19+
20+
echo "Running custom boot task..."
21+
```
22+
23+
### 2. Set Permissions and Ownership
24+
Make the script executable and ensure it’s owned by `root`:
25+
26+
```bash
27+
sudo chown root:root /mnt/jrc-comms/hooks/boot.d/99-custom-task
28+
sudo chmod +x /mnt/jrc-comms/hooks/boot.d/99-custom-task
29+
```
30+
31+
### 3. Verify Execution Order
32+
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:
33+
34+
- `05-mount-recovery-mount` runs first (found in `/opt/jrc/hooks/boot.d`)
35+
- `10-cluster-clean` runs next (found in `/opt/jrc/hooks/boot.d`)
36+
- `99-custom-task` runs last (added to `/mnt/jrc-comms/hooks/boot.d`)
37+
38+
**Key rules:**
39+
- Prefixes determine execution order (e.g., `00-` to `99-`)
40+
- Use two-digit numbering for clarity (e.g., `05-`, `10-`, `99-`)
41+
- Scripts with the same prefix may execute in lexicographical order, but avoid ambiguity by using unique prefixes
42+
- Scripts added to `/mnt/jrc-comms/hooks/boot.d` will persist AMI upgrades, stack clones, etc.
43+
44+
---
45+
46+
## Example Walkthrough
47+
To log system time at the end of the boot process:
48+
49+
```bash
50+
#!/bin/bash
51+
/mnt/jrc-comms/hooks/boot.d/99-custom-task
52+
53+
LOGFILE="/var/log/custom-boot.log"
54+
echo "Boot completed at: $(date)" >> $LOGFILE
55+
```
56+
57+
---
58+
59+
## Troubleshooting Tips
60+
1. **Test your script manually** before relying on the boot process:
61+
62+
```bash
63+
sudo /mnt/jrc-comms/hooks/boot.d/99-custom-task
64+
```
65+
66+
2. **Check logs** for errors (e.g., `/var/log/syslog` or `journalctl`)
67+
68+
3. **Validate script syntax** using:
69+
70+
```bash
71+
bash -n /mnt/jrc-comms/hooks/boot.d/99-custom-task
72+
```
73+
74+
By following this structure, you can extend the boot process with custom logic while maintaining predictable execution order.
75+
76+
---
77+
78+
### Alternative to fstab Mounting Using Boot Hook Script
79+
80+
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.
81+
82+
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`.
83+
84+
## Boot Hook Script Implementation
85+
86+
### 1. Create /mnt/jrc-comms/hooks/boot.d/99-links Script
87+
88+
Creates bind mounts after filesystems are available
89+
90+
```bash
91+
#!/bin/bash
92+
/mnt/jrc-comms/hooks/boot.d/99-links
93+
94+
echo "Creating bind mounts..."
95+
mount --bind /var/www/domain.com/shared/var/salesexport /home/user/salesexport
96+
mount --bind /var/www/domain.com/shared/media/importexport /home/user/importexport
97+
```
98+
99+
### 2. Set Permissions
100+
101+
```bash
102+
sudo chmod +x /mnt/jrc-comms/hooks/boot.d/99-links
103+
sudo chown root:root /mnt/jrc-comms/hooks/boot.d/99-links
104+
```
105+
106+
## Verification
107+
1. **Validate script syntax**:
108+
109+
```bash
110+
bash -n /mnt/jrc-comms/hooks/boot.d/99-custom-task
111+
```
112+
113+
2. **Check active mounts**:
114+
115+
```bash
116+
mount | grep bind
117+
```
118+

0 commit comments

Comments
 (0)