Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why doesn't my application behave the same when it's launched by systemd.service as when it's launched manually?

I’ve got a dotnet API running on my raspberry, when I lauch the executable manually, it listens on
http://<raspberry_ip>:<custom-port> as configured on my appsettings.json but when I use it as a service on my raspberry boot, it lauches on http://localhost:5000.

I know something must be missing in my /lib/systemd/system/<app>.service but I failed to see what.

My service configuration :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[Unit]
Description=Lauches API on boot
After=multi-user.target

[Service]
ExecStart=/home/<user>/Dev/<app_executable>
User=<user>

[Install]
WantedBy=multi-user.target

It seems quite strange, is this because of the moment the service lauches (too soon?) or am I missing something else in my configuration ?

Thanks a lot.

Ps: I also tried to change ExecStart and provide my dotnet path like so :
ExecStart = /<dotnet_path> /<app_path>.dll but it didn’t work either.

>Solution :

You need to set the WorkingDirectory parameter.

According to the docs:

WorkingDirectory=
Takes a directory path relative to the service’s root directory specified by RootDirectory=, or the special value "~". Sets the
working directory for executed processes. If set to "~", the home
directory of the user specified in User= is used. If not set, defaults
to the root directory when systemd is running as a system instance and
the respective user’s home directory if run as user. If the setting is
prefixed with the "-" character, a missing working directory is not
considered fatal. If RootDirectory=/RootImage= is not set, then
WorkingDirectory= is relative to the root of the system running the
service manager. Note that setting this parameter might result in
additional dependencies to be added to the unit (see above).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading