0

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
2
  • 1
    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 Nov 16, 2017 at 5:47
  • @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
    Nov 16, 2017 at 7:09

2 Answers 2

2

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

10
  • I am getting this error when I execute this -> sudo systemctl enable myapp Failed to execute operation: No such file or directory
    – Galet
    Nov 16, 2017 at 9:49
  • 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
    – Galet
    Nov 16, 2017 at 9:55
  • The command was the one you used ealier: sudo update-rc.d myapp defaults Nov 16, 2017 at 10:24
  • 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
    – Galet
    Nov 16, 2017 at 10:46
  • That's cause it's not setup well use systemd Nov 16, 2017 at 12:34
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.