Monday, 6 August 2018

Deploy Your .Net-Core-service to run as Service in Ubuntu



step 1:  publish the code

step 2: > sudo nautilus -- to open file explorer in ubuntu
   > paste the code into /opt/ServiceFolder

step 3: > cd /etc/systemd/system

step 4: > gedit syslog.service &

step 5: > copy and paste the same content into a new file

step 6: > you will find 3 section
[Unit]

[Service]

[Install]

step 7: > [Unit]
       Description=Your Service Name

Step 8: > [Service]
                ExecStart=/usr/bi/dotnet /opt/ServiceFolder/service.dll
        Restart=always

(we need dotnet command to lunch application, and its path, you can find by using [which dotnet] from terminal )

Step 9: > [Install]
       WantedBy=default.target

(The dictation processor doesn't have any special need here, so you can just specify the default target.)


step 10: > then save it into /etc/systemd/system folder with proper name : such as myservice-processor.service

Step 11: > you can now use systemd to control your service.

step 12: > 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 journalctl command a try. use the -u switch to pass it the name of our unit or service which is 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 untill you pass enable systemctl for this unit. go ahead and do it

> sudo systemctl enable myservice-processor


(you notice that enabling creates a symlink. by doing so, systemd hooks the myservice-processor into the system init.


step 15: > now if you restart your machine , and check the service status again the myservice-processor is already running.


 


No comments:

Post a Comment