1

I have a .NET Core application (self contained) which I've copied to the folder /home/ubuntu/TimberApi in an Ubuntu LightSail instance. I am trying to start it as a service. It is complaining that the unit file is invalid. Can anyone spot an error in the file?

This is the contents of the service file:

Description=Timber Store Api

[Service]
WorkingDirectory=/home/ubuntu/TimberApi
ExecStart=/home/ubuntu/TimberApi/TimberStore.Api
Restart=always
RestartSec=10
SyslogIdentifier=offershare-web-app
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

Here is the error:

Failed to start TimberStoreApi.service: Unit TimberStoreApi.service has a bad unit file setting.
See system logs and 'systemctl status TimberStoreApi.service' for details.

I ran systemctl status TimberStoreApi.service and got this:

/etc/systemd/system/TimberStoreApi.service:5: WorkingDirectory= path is not absolute: ~/TimberApi
2
  • Is TimberStore.Api an executable?
    – Alex
    Sep 13, 2021 at 14:39
  • Should be an executable @Alex (because it runs when I type ./TimberStore.Api). Forgive me for my lack of understanding about linux file types. Sep 13, 2021 at 14:52

1 Answer 1

2

From the error message, it looks like the Working Directory line used to be WorkingDirectory=~/TimberApi but has been edited to its current form WorkingDirectory=/home/ubuntu/TimberApi without running systemctl daemon-reload afterwards, so systemd is still using the old version.

So just running systemctl daemon-reload should fix it.

If you use the systemctl edit <some.service> command, it will automatically execute systemctl daemon-reload for you when needed. But if you edit the service files directly, then you'll have to run systemctl daemon-reload, or else your changes won't take effect until you reboot the system.

3
  • Yes, you are correct. It used to be ~/TimberApi. I have tried "systemctl daemon-reload" a few times, but it stiill gives me the same error unfortunately. I even rebooted the machine. Sep 13, 2021 at 14:48
  • That is strange. Try running cat -A /etc/systemd/system/TimberStoreApi.service. It will make any invisible non-space characters visible: each end-of-line will be marked with an $, any control characters will appear as regular characters with a ^ prefixed to them, and other special characters are displayed with a M- prefix. If you have edited the file in Windows, you might now see ^M$ at the end of each line: it means the file has Windows-style end-of-line characters, and you might want to convert the file to Unix-style end-of-lines, using e.g. fromdos or dos2unix commands.
    – telcoM
    Sep 13, 2021 at 14:56
  • Thank you very much for the response @telcoM. For some reason, my previous edit hadn't been saved. Now the service starts successfully. Sep 13, 2021 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .