# 🥾Delayed Reboot Script for Debian Controlled by systemd 👟

To create a **systemd service** that runs `/usr/local/sbin/custom-reboot.sh` **once**, exactly **3 minutes after boot**, follow these steps:

---

### **Step 1: Create the Systemd Service File**

Open a terminal and create a new systemd service file:

```plaintext
sudo nano /etc/systemd/system/custom-reboot.service
```

Add the following content:

```plaintext
[Unit]
Description=Run Custom Reboot Script Once After Boot
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/sbin/custom-reboot.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
```

* `Type=oneshot`: Ensures the script runs **once**.
    
* `RemainAfterExit=yes`: Prevents systemd from considering the service as inactive immediately.
    
* `After=`[`network.target`](http://network.target): Ensures the network is up before running the script.
    
* `ExecStart=/bin/bash /usr/local/sbin/`[`custom-reboot.sh`](http://custom-reboot.sh): Runs the script.
    

---

### **Step 2: Create a Timer to Delay Execution**

Now, create a **timer** that runs the service **3 minutes after boot**:

```plaintext
sudo nano /etc/systemd/system/custom-reboot.timer
```

Add the following content:

```plaintext
[Unit]
Description=Run Custom Reboot Script 3 Minutes After Boot
After=network.target

[Timer]
OnBootSec=3min
Unit=custom-reboot.service

[Install]
WantedBy=timers.target
```

* `OnBootSec=3min`: Runs the service **3 minutes after boot**.
    
* `Unit=custom-reboot.service`: Links the timer to the service.
    

---

### **Step 3: Reload Systemd and Enable the Timer**

Reload systemd and enable the timer:

```plaintext
sudo systemctl daemon-reload
sudo systemctl enable custom-reboot.timer
sudo systemctl start custom-reboot.timer
```

To **verify** that the timer is active:

```plaintext
systemctl list-timers --all | grep custom-reboot
```

---

### **Step 4: Test the Setup**

To test the setup manually **without rebooting**:

```plaintext
sudo systemctl start custom-reboot.service
```

To check the logs:

```plaintext
journalctl -u custom-reboot.service --no-pager --since "5 minutes ago"
```

---

### **Step 5: Ensure the Script is Executable**

Make sure `/usr/local/sbin/custom-reboot.sh` exists and is **executable**:

```plaintext
sudo chmod +x /usr/local/sbin/custom-reboot.sh
```

---

### **Wrap**

✅ Now, your **custom script** will **automatically** run **once, exactly 3 minutes after boot**! 🚀
