How to configure to start my application at boot time

8,962

Solution 1

The old way is System V and UpStart but the new way is systemd. The steps are:

  1. Create the service file in /etc/systemd/system/myapp.service:

    • contents might be (depending on your service needs):

      [Unit]
      Description=myapp service            
      
      [Service]
      Type=simple            
      ExecStart=/path/to/myapp.sh            
      
      [Install]
      WantedBy=multi-user.target
      
  2. Start it: sudo systemctl start myapp

  3. Get it to run at boot: sudo systemctl enable myapp
  4. Other commands of systemctl:
    • stop it: sudo systemctl stop myapp
    • disable it: sudo systemctl disable myapp

Please see:

https://www.freedesktop.org/software/systemd/man/systemd.service.html

Solution 2

All you need is /etc/systemd/system/myapp.service.

To start: sudo systemctl start myapp

To stop: sudo systemctl stop myapp

To start at boot: sudo systemctl enable myapp

Share:
8,962
Galet
Author by

Galet

Updated on September 18, 2022

Comments

  • Galet
    Galet over 1 year

    How to configure to start my application at boot time in Ubuntu 16.04

    I am using following files to setup my application as a service.

    /etc/init.d/myapp
    /etc/systemd/systedm/myapp.service
    /usr/local/myapp/myapp.sh
    

    To start my application at boot time , I have used following command, but it throws error. How can I resolve this issue?

    sudo update-rc.d paxata-server defaults 
    insserv: script paxata-server is not an executable regular file, skipped!
    insserv: warning: script 'hst' missing LSB tags and overrides
    
    • George Udosen
      George Udosen over 6 years
      Why are you using both /etc/init.d/myapp, and /etc/systemd/systedm/myapp.service files at the same time either use init scripts or use systemd service files
    • Galet
      Galet over 6 years
      @George I don't know which files should be mandatory. I want to start my app using "service myapp start" and start at boot. what are the steps for that.
  • Galet
    Galet over 6 years
    I am getting this error when I execute this -> sudo systemctl enable myapp Failed to execute operation: No such file or directory
  • Galet
    Galet over 6 years
    Currently I am using service command to start/stop services (e.g. service paxata-server start). Is there any service command to start my service at boot
  • George Udosen
    George Udosen over 6 years
    The command was the one you used ealier: sudo update-rc.d myapp defaults
  • Galet
    Galet over 6 years
    sudo update-rc.d myapp defaults insserv: script myapp is not an executable regular file, skipped! insserv: warning: script 'hst' missing LSB tags and overrides
  • George Udosen
    George Udosen over 6 years
    That's cause it's not setup well use systemd
  • Galet
    Galet over 6 years
    Tried sudo systemctl enable myapp and sudo update-rc.d myapp defaults. How to start using systemd?
  • George Udosen
    George Udosen over 6 years
    Now if sudo systemctl enable myapp worked do systemctl status myapp to check the status, and since I don't know what is in your script you alone should be able to tell if it works as expected...
  • Galet
    Galet over 6 years
    I am getting error for both commands 1. sudo systemctl enable myapp 2. sudo update-rc.d myapp defaults. Refer my previous comments.
  • George Udosen
    George Udosen over 6 years
    Get rid of the myapp file in /etc/init.d and use only the one in /etc/systemd/system.
  • Galet
    Galet over 6 years