-1

Greetings. I'm currently automating a python script to run on boot of Ubuntu system. Everything works fine when i set up my service and manually starting it. But when i reboot my system and checked the status i encountered this error. enter image description here

Here is mysmtp.service:

[Unit]
Description=My Smtp Service
After=multi-user.target

[Service]
Type=idle
WorkingDirectory=<my path script dir>
ExecStart=/usr/bin/python smtp.py

[Install]
WantedBy=multi-user.target

Here is the command i execute:

sudo chmod +x <my path script>
sudo systemctl enable mysmtp.service
sudo systemctl start mysmtp.service

Thanks

iamcoder
  • 529
  • 2
  • 4
  • 23
  • 1
    Seems like more of a config question so might it be a better fit for https://askubuntu.com/ ? – Paul Rooney Jun 21 '17 at 00:39
  • @PaulRooney Hi Sir yes i will try to post a question on askubuntu.com -thanks – iamcoder Jun 21 '17 at 01:08
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jun 21 '17 at 19:51

1 Answers1

0

Regarding this...

sudo chmod +x <my path script>

Does your script start with a shebang? #!/usr/bin/env python?

If so, you do not need to specify /usr/bin/python is your ExecStart, or really WorkingDirectory.

Give the full path in the ExecStart to <my path script dir>/smtp.py

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • my mistake here, yup it was sudo chmod +x /smtp.py I already did the inputting the full path on ExecStart but still when i reboot my ubuntu system and checking the status it was the error i've screened shot. – iamcoder Jun 21 '17 at 01:07
  • Well, your screenshot currently says "can't find file". So, is the file being deleted when you reboot? Or the service can't read the directory where the file exists? – OneCricketeer Jun 21 '17 at 01:10
  • And owned by your user, I'm guessing? The system init process might not be running as root – OneCricketeer Jun 21 '17 at 01:17
  • when i check by ls -l /home//smtp.py the result is -rwxr-xr-x 1 862 Jun 21 10:12 smtp.py is it correct? – iamcoder Jun 21 '17 at 01:20
  • That's fine for the script, now what about `ls -l /home`? – OneCricketeer Jun 21 '17 at 01:21
  • I think you might be able to have something like this to use your user account https://stackoverflow.com/a/26565328/2308683 – OneCricketeer Jun 21 '17 at 01:22