Ubuntu 18.04 : how to run start up script

  1. Create a service:
    sudo vi /etc/systemd/system/rc-local.service
    
  2. Add your code there:
    [Unit]
    Description=/etc/rc.local Compatibility
    ConditionPathExists=/etc/rc.local
    
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    StandardOutput=tty
    RemainAfterExit=yes
    SysVStartPriority=99
    
    [Install]
    WantedBy=multi-user.target
    
  3. Create and make sure /etc/rc.local is executable and add this code inside it:
    sudo chmod +x /etc/rc.local
    #!/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.
    
    exit 0
    
  4. Enable the service:
    sudo systemctl enable rc-local
    
  5. Start service and check status:
    sudo systemctl start rc-local.service
    sudo systemctl status rc-local.service
    
  6. If all goes well you can add your code to the /etc/rc.local file then restart it.

Leave a Reply

Your email address will not be published. Required fields are marked *