4

I'm looking for a method to start an application immediately after boot-up. This application times out after 1 hour. I'd like to then start another instance of this application 1 hour after the initial boot-up (following the timeout of the initial application). I had been thinking that Cron might be configured (cleverly) to accomplish this. Short of resetting the system clock to 00:00:00 at boot-up and then running Cron normally, is there a way to do this? Thanks in advance.

Update: Based on maulinglawn's advice I have gone with the Systemd.service method. Specifically, I've put a copy of my python script in /usr/bin/startVideo/startVideo.py. Then created a service file in /lib/systemd/service/startVideo.service. Here's that file,

[Unit] Description=starts video recorder [Service] Type=simple ExecStart=/usr/local/bin/startVideo/startVideo.py Restart=always [Install] WantedBy=multi-user.target 

Finally I ran,

sudo systemctl enable startVideo.service 

to register the service. This will be running on a Raspberry Pi3 wired to a video camera with no monitor or keyboard attached. I'm just looking for the system to record video 24/7 and have the capability to restart itself in the event of a power failure. Other suggestions? Is "WantedBy" configured correctly for this type of application?

Massively grateful for this solution and steerage away from Cron-ville.

1
  • I guess the challenge here is that 'boot-up' can occur at any minute which is why a standard crontab wouldn't work. What about a boot up script that creates the crontab entry? The minute field gets set based on date/time when the script is run. Commented Oct 11, 2016 at 6:37

2 Answers 2

2

Given your description, I would start the application with a systemd (since that is what I have on all my machines) .service file.

In that service file, I would point to a script that wraps your application in a simple while loop. Something like this:

#!/bin/sh while true; do /path/to/your/application done 

This way, every time your application dies ("times out"), it will restart on its own since the condition for the loop is always true.

This is one approach, and the simplest I can think of, there may be others!

4
  • Love this. The bottom line is that the application needs to always be running. The one-hour window is arbitrary, some users might want another time frame...this would account for that. Commented Oct 11, 2016 at 15:08
  • @portsample Glad to hear. If this solved your issue, please mark the question as solved. Best regards! Commented Oct 11, 2016 at 15:28
  • Will do once I implement a solution. Commented Oct 11, 2016 at 21:15
  • @portsample "Massively grateful for this solution and steerage away from Cron-ville." I laughed at that! Great that you managed to implement a solution. Good work! Commented Oct 12, 2016 at 6:25
0

For those not in love with systemd, an invocation of the the program('s shell-wrapper) in /etc/rc.local ( on e.g. Debian ) with a pidfile in /var/run is good. Something like while true ; do $_cmd >/dev/null 2>&1 & sleep 3600 ; pkill $( cat /var/run/pgm.pid ) ; rm /var/run/pgm.pid ; done - assuming your daemon can write its own pid. Otherwise some ps text-fu is necessary to only signal the parent process, not its children. man ps.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.