Deploy Your .Net Core service to run as Service in Ubuntu - Avinashlikes/Wiki GitHub Wiki
Step 1 : Publish your dot net core service
Step 2 : Open file explorer in ubuntu
sudo nautilus
Step 3 : Paste that code into
/opt/ServiceFolder
Step 4 : Go to system folder
cd /etc/systemd/system
Step 5 : Edit one of the system service e.g:
gedit syslog.service &
Step 6 : Duplicate this service by copying & pasting the same content into a new file
Step 7 : This service file contains mainly three section
[Unit]
[Service]
[Install]
Step 8 : [Unit] Contains service description
[Unit]
Description=Your Service Name
Step 9 : [Service] Contains steps to execute service
[Service]
ExecStart=/usr/bin/dotnet /opt/ServiceFolder/service.dll
Restart=always
Note: We need dotnet command to lunch application, and its path, you can
find by using [which dotnet] from terminal.
Step 9 : [Install] where to install
[Install]
WantedBy=default.target
Note: The dictation processor doesn't have any special need here, so you can just specify the default target.
Step 10 : Save it into
/etc/systemd/system folder with proper name : such as myservice-processor.service
Step 11 : You can now use
systemdto control your service.
Step 12 : > List of systemd command
1) systemctl status myservice-processor
2) q - to quit from command
3) sudo systemctl start myservice-processor
4) sudo systemctl status myservice-processor
Step 13 : Lets give the
journalctlcommand a try. use the -u switch to pass it the name of our unit e.g:myservice-processor, and use the -f switch to follow the journal live.
sudo journalctl -u myservice-processor -f
Step 14 : Now, since you defined in the service file, how the service would start on boot, but it won't actually do so until you
enable systemctlfor this unit
sudo systemctl enable myservice-processor
Note: you notice that enabling creates a symlink. By doing so,``` systemd ``` hooks the myservice-processor into the system init.
Step 15 : Now if we restart our machine , and check the service status again the
myservice-processoris already running.