0

I have never done a service before in linux perse, but I been trying to make a service using a Pi.

I used 2 different approaches to create a service. The first approach was using the systemctl using as base the code posted near the end of https://ubuntuforums.org/showthread.php?t=2318279. In my case the ExecStart looks like follow: ExecStart=/home/pi/berryconda2/bin/python /home/pi/Documents/MyCode.py When I start this service using sudo systemctl start MyCode.service it appears as active and running until I execute a another that live in my PC and not in the Pi (they communicate with each other), then I get

  • (code=exited, status=2)
  • Unit entered failed state.
  • Failed with result 'exit-code'.

If I run MyCode.py using my default python interpreter my code work, but I want the pi to run the since boot and continue to run it until I turn it off.

Now for my second approach I utilize the steps describe here http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/. At the end when I run my .sh, I get

  • active (exited)
  • (code=exited,status=0/SUCCESS).

As describe in the later link, I run start-stop-daemon --start --pidfile /var/run/MyCode_service.pid --make-pidfile --user root --startas /home/pi/Documents/MyCode.py -- --log /var/log/MyCode_service.log and it work. I'm not sure how to properly debug this services. I have look at https://freedesktop.org/software/systemd/man/systemd.exec.html#id-1.20.8 and http://manpages.ubuntu.com/manpages/cosmic/en/man8/start-stop-daemon.8.html. But I quiet haven't figure it out yet. Can someone point me in the right direction or know of any other building blocks for making a service? or at least trouble shoot it?

CodeAndvil
  • 15
  • 1
  • 6
  • Not sure what you are trying to do. But you are probably reading the old info from the wrong place ,ubuntu is not exactly the raspbian. To create a systemd service can be quite simple as describe [here](https://www.raspberrypi.org/documentation/linux/usage/systemd.md). For better understanding on systemd, read [this](https://docs.fedoraproject.org/en-US/quick-docs/understanding-and-administering-systemd/index.html) – hcheung Jan 08 '19 at 01:15
  • Thank you @hcheung, that links are very useful. I decided to use supervisor to run my script and it work, but then I realize that I needed to make super visor run at boot as well. When I check the supervisor log I got the following line at the end: 2019-01-10 15:09:27,430 INFO stopped: MySupervisorProgram (terminated by SIGTERM). My guessing is that the service ExecStart and ExecStop run, but the service never restart. But I still figuring out the systemd service. – CodeAndvil Jan 10 '19 at 15:31
  • My Service script looks as follow: `[Unit] Description=Supervisor Service [Service] Type=Simple User=root WorkingDirectory=/home/pi/supervisor ExecStart=/home/pi/berryconda2/bin/supervisord -c supervisord.conf ExecStop=/home/pi/berryconda2/bin/supervisoctl $OPTIONS shutdown ExecReload=/home/pi/berryconda2/bin/supervisoctl -c supervisord.conf $OPTIONS reload KillMode=process Restart=on-failure RestartSec=50s [Install] WantedBy=multi-user.target` By @AlexChiang from [post](https://stackoverflow.com/questions/37404384/supervisor-3-3-with-ubuntu-16-04-service-start-failure) – CodeAndvil Jan 10 '19 at 16:11

0 Answers0