3

I am trying to create a service to run by .net application on ubuntu 18.04.

cd /lib/systemd/system/YellowPages.service

[Unit]
Description = Yellow pages .NET service

[Service]
Type=forking
WorkingDirectory=/home/yp_app
ExecStart=dotnet /home/yp_app/YellowPages.dll

[Install]
WantedBy=multi-user.target
~

I have my application on /home/yp_app.

when I run:systemd start YellowPages.service I get Excess arguments.

so I tried with: systemctl start YellowPages.service I get

 Failed to start YellowPages.service: Unit YellowPages.service is not loaded properly: Exec format error.
See system logs and 'systemctl status YellowPages.service' for details.

When I look into cat /var/log/syslog

I could see

systemd[1]: /lib/systemd/system/YellowPages.service:7: Executable path is not 
absolute: dotnet /home/yp_app/YellowPages.dll

I am new to Linux I am wondering where I am wrong. Could anyone help me with this?

sumanth shetty
  • 1,851
  • 5
  • 24
  • 57

1 Answers1

5

There are a couple of issues with your daemon:

[Unit]
Description = Yellow pages .NET service

Remove spaces around equal sign:

[Unit]
Description=Yellow pages .NET service

ExecStart needs an absolute path (hence the error):

[Service]
Type=forking
WorkingDirectory=/home
ExecStart=/usr/bin/dotnet /home/yp_app/YellowPages.dll

Your dotnet executable might be located elsewhere, although you can find out its absolute path by doing:

$ which dotnet

Whatever is returned would be the absolute path to use.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • did the changes not getting that error no more . But when I try to enable the service by: systemctl enable YellowPages.service: Failed to enable unit: Invalid argument – sumanth shetty Jul 02 '20 at 03:07
  • when I check the syslogs i see: CRON[8868]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) – sumanth shetty Jul 02 '20 at 03:09
  • @sumanthshetty: Show the command you are attempting to start the service. It should simply be: `systemctl start Yellowpages`. The second comment with the `cron` error is unrelated. If it doesn’t work use `journalctl -xe` immediately after and post the output. – l'L'l Jul 02 '20 at 03:27
  • @I'L'I i used systemctl start Yellowpages.service Failed to start YellowPages.service: Unit YellowPages.service is not loaded properly: Exec format error. See system logs and 'systemctl status YellowPages.service' for details. when I check the syslog /lib/systemd/system/YellowPages.service:7: Working directory path 'home/yp_app' is not absolute. how do I find the absolute path of the app folder. i sued PWD – sumanth shetty Jul 02 '20 at 03:34
  • It looks like you are missing the `/` at the beginning of `home/ypp...`. When you are on the working directory try: `pwd`, it should return the full absolute path. – l'L'l Jul 02 '20 at 23:02