30 ก.ค. 2567

Create rc.local in Ubuntu 22

 1. Create the rc.local file:

sudo nano /etc/rc.local

2. Add your commands:


#!/bin/sh -e

#

# rc.local

#

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

iptables-restore < /iptables.firewall

exit 0


3. Make the script executable:

sudo chmod +x /etc/rc.local

4. Create a systemd service file to run the script:

sudo nano /etc/systemd/system/rc-local.service

5. Add the following content to the service file:

[Unit]
Description=Local Startup Script

[Service]
Type=simple
ExecStart=/etc/rc.local

[Install]
WantedBy=multi-user.target

6. Make the service executable:

sudo chmod 644 /etc/systemd/system/rc-local.service

7. Enable and start the service:

sudo systemctl enable rc-local.service
sudo systemctl start rc-local.service

8. Verify the script is running:

sudo systemctl status rc-local.service

ไม่มีความคิดเห็น:

แสดงความคิดเห็น