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:
-
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
-
Start it:
sudo systemctl start myapp
- Get it to run at boot:
sudo systemctl enable myapp
- Other commands of systemctl:
- stop it:
sudo systemctl stop myapp
- disable it:
sudo systemctl disable myapp
- stop it:
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
Author by
Galet
Updated on September 18, 2022Comments
-
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 over 6 yearsWhy are you using both
/etc/init.d/myapp
, and/etc/systemd/systedm/myapp.service
files at the same time either useinit scripts
or usesystemd
service files -
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 over 6 yearsI am getting this error when I execute this -> sudo systemctl enable myapp Failed to execute operation: No such file or directory
-
Galet over 6 yearsCurrently 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 over 6 yearsThe command was the one you used ealier:
sudo update-rc.d myapp defaults
-
Galet over 6 yearssudo 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 over 6 yearsThat's cause it's not setup well use
systemd
-
Galet over 6 yearsTried sudo systemctl enable myapp and sudo update-rc.d myapp defaults. How to start using systemd?
-
George Udosen over 6 yearsNow if
sudo systemctl enable myapp
worked dosystemctl 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 over 6 yearsI am getting error for both commands 1. sudo systemctl enable myapp 2. sudo update-rc.d myapp defaults. Refer my previous comments.
-
George Udosen over 6 yearsGet rid of the myapp file in
/etc/init.d
and use only the one in/etc/systemd/system
. -
Galet over 6 yearsLet us continue this discussion in chat.