Vipul Tyagi
Vipul Tyagi

Reputation: 667

Cannot run python program as a service in ubuntu 18.04

I am trying to run a python program as a background service in ubuntu 18.04. It imports zerorpc module which I have already installed with pip3 and tested with python command on terminal. But it shows status: failed when I try to run the program as dummy.service. Below is my service file:

[Unit]
Description=Dummy Service
[Service]
Type=Simple
ExecStart=/usr/bin/python3 /usr/bin/server.py
[Install]
WantedBy=multi-user.target

Below is the status of serice after enabling it:

dummy.service - Dummy Service
Loaded: loaded (/lib/systemd/system/dummy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-11-26 16:18:57 IST; 5s ago 

Process: 4101 ExecStart=/usr/bin/python2 /usr/bin/server.py (code=exited, status=1/FAILURE)
Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: Started Dummy Service.

Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: Traceback (most recent call last):

Nov 26 16:18:57 vipul-HP-Notebook python2[4101]:   File "/usr/bin/server.py", line 1, in <module>

Nov 26 16:18:57 vipul-HP-Notebook python2[4101]:     import zerorpc

Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: ImportError: No module named zerorpc

Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: dummy.service: Main process exited, code=exited,      status=1/FAILURE

Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: dummy.service: Failed with result 'exit-code'.

I don't know why this is happening. Please help!!

Upvotes: 2

Views: 1514

Answers (1)

Vipul Tyagi
Vipul Tyagi

Reputation: 667

If your daemon service is giving error in importing module, the probably you have installed it with pip only. Installing module this way makes it available to a specific user, if you want to make it available globally, you would have to install it with admin privileges like this:

sudo -H pip3 install module_name

Upvotes: 3

Related Questions