0

I've got a small project that's based around a raspberry pi. A central part of this project is for my program to be executed on start-up and run until shutdown, all while running stand-alone (that means no SSH). One way I've found is to run my program with nohup, but this still requires an ssh session to start.

I've written the program following the guidelines for creating a linux daemon, yet when I execute it as sudo ./myprogram, it doesn't actually seem to be running as root (it can't to write to the GPIO pins). What is the proper way of going about this?

  • 1
    What Linux distribution are you running on your Raspberry Pi? (Raspbian?) That information might be helpful in figuring out what to do... Your system should have a set of init scripts that run during boot (for instance, look for an /etc/init.d directory.) That's usually the proper place to configure scripts to launch daemons on start up. – filbranden May 4 '18 at 5:52
  • Yes, it's the latest version of raspbian. I took a look at that directory but am not sure how to make my own. Is it enough to just do DAEMON=/usr/bin/myDaemon and place my daemon executable in /usr/bin/? – Astrum May 4 '18 at 6:24
  • 1
    Please state the version you are using, "The latest one" is changing over time! – MatsK May 4 '18 at 6:28
0

You can use systemd services to get this job done. It's easier to control your application via systemd have a look at this tutorial https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

  • Welcome to unix stackexchange and thanks for your reply. While providing sources is always good, it would really help if you could provide an example, links can break. – thecarpy May 4 '18 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.