Mlapi start as a service

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
Post Reply
JasonBorn
Posts: 37
Joined: Fri Jan 08, 2021 5:31 pm

Mlapi start as a service

Post by JasonBorn »

Hi there,
i cant start the MLAPI as a service. I get this error:

Code: Select all

● mlapi.service - Machine Learning API service
     Loaded: loaded (/etc/systemd/system/mlapi.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2021-06-05 09:43:29 CEST; 1s ago
    Process: 17336 ExecStart=/var/lib/zmeventnotification/mlapi/mlapi.py -c ./mlapiconfig.ini (code=exited, status=209/STDOUT)
    Process: 17337 ExecStartPost=/bin/sh -c umask 022; pgrep mlapi.py > /var/run/mlapi.pid (code=exited, status=209/STDOUT)
   Main PID: 17336 (code=exited, status=209/STDOUT)

Jun 05 09:43:29 mlapi systemd[1]: Failed to start Machine Learning API service.

Is there any special option to start it? Manually the MLAPI starts.


EDIT:
systemctl status mlapi.service shows:

Code: Select all

● mlapi.service - Machine Learning API service
     Loaded: loaded (/etc/systemd/system/mlapi.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2021-06-05 09:57:07 CEST; 2s ago
    Process: 20224 ExecStart=/var/lib/zmeventnotification/mlapi/mlapi.py -c ./mlapiconfig.ini (code=exited, status=209/STDOUT)
    Process: 20225 ExecStartPost=/bin/sh -c umask 022; pgrep mlapi.py > /var/run/mlapi.pid (code=exited, status=209/STDOUT)
   Main PID: 20224 (code=exited, status=209/STDOUT)

Jun 05 09:57:07 mlapi systemd[20225]: mlapi.service: Failed at step STDOUT spawning /bin/sh: No such file or directory
Jun 05 09:57:07 mlapi systemd[20224]: mlapi.service: Failed at step STDOUT spawning /var/lib/zmeventnotification/mlapi/mlapi.py: No such file or directory
Jun 05 09:57:07 mlapi systemd[1]: mlapi.service: Main process exited, code=exited, status=209/STDOUT
Jun 05 09:57:07 mlapi systemd[1]: mlapi.service: Control process exited, code=exited, status=209/STDOUT
Jun 05 09:57:07 mlapi systemd[1]: mlapi.service: Failed with result 'exit-code'.
Jun 05 09:57:07 mlapi systemd[1]: Failed to start Machine Learning API service.
~
But mlapy.py is there:

Code: Select all

-rw-rw-r--  1 www-data www-data  5083 Jun  4 19:44 CHANGELOG.md
-rw-rw-r--  1 www-data www-data     6 Jun  4 19:44 LICENSE
-rw-rw-r--  1 www-data www-data  8444 Jun  4 19:44 README.md
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:56 db
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:44 examples
-rwxrwxr-x  1 www-data www-data  5693 Jun  4 19:44 get_models.sh
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:44 images
-rwxrwxr-x  1 www-data www-data  3013 Jun  5 08:53 install_as_service.sh
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:44 known_faces
-rwxrwxr-x  1 www-data www-data   326 Jun  4 19:44 make_changelog.sh
-rwxrwxr-x  1 www-data www-data   532 Jun  4 19:44 make_tag.sh
-rwxr-xr-x  1 www-data www-data 15525 Jun  5 08:54 mlapi.py
-rw-rw-r--  1 www-data www-data  1408 Jun  5 09:42 mlapi.service
-rw-rw-r--  1 www-data www-data  2025 Jun  4 19:44 mlapi_dbuser.py
-rwxr-xr-x  1 www-data www-data   676 Jun  5 08:54 mlapi_face_train.py
-rwxr-xr-x  1 www-data www-data   429 Jun  5 08:54 mlapi_logrot.sh
-rw-rw-r--  1 www-data www-data 12846 Jun  5 09:31 mlapiconfig.ini
drwxrwxr-x  7 www-data www-data  4096 Jun  4 19:47 models
drwxrwxr-x  3 www-data www-data  4096 Jun  4 19:56 modules
drwxrwxr-x 14 www-data www-data  4096 Jun  4 20:05 opencv
-rw-rw-r--  1 www-data www-data   198 Jun  4 19:44 requirements.txt
-rw-rw-r--  1 www-data www-data   222 Jun  4 20:55 secrets.ini
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:44 tools
drwxrwxr-x  2 www-data www-data  4096 Jun  4 19:44 unknown_faces
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Mlapi start as a service

Post by asker »

mlapi doesn't come with a generic service activation. You'll have to write or customize your own.
The mlapi.service file I provide is one that works for me (Ubuntu 20) and the install_as_service.sh script set its up (which explains the disclaimer in the script).

So I am not sure how you have defined your service file but I'd suspect that is where you should start.
You may also want to search for "Failed at step STDOUT spawning /bin/sh" on Google. One option is "/bin/sh" is actually "/usr/bin/sh" (in my case)

All that being said, there may be others who are well versed in writing service files who may know what is going on.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
JasonBorn
Posts: 37
Joined: Fri Jan 08, 2021 5:31 pm

Re: Mlapi start as a service

Post by JasonBorn »

ok got it. Thank you for your help.
I have to comment out that lines:
StandardOutput=file:/var/log/zm/mlapi.log
StandardError=file:/var/log/zm/mlapi_error.log
Post Reply