I want the camera on my pi (Rpi 3B+) to take a picture every time it boots up. I've read through several other questions of people trying to do similar things, but I haven't ever found the script that was used to successfully achieve it. This is the first script I've written, so I'm guessing that the problem is with the script, rather than the init.d setup as that part is pretty easy to follow

Here's what I have:

# /etc/init.d/startup.sh
# Provides:          startup.sh
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.

raspistill --annotate 12 -o /home/pi/Pictures/Startup/Startup_`date +%d%m%Y_%H%M-%S`.jpg
  1. I saved this to /etc/init.d/startup.sh
  2. then used sudo chmod +x startup.sh to make it executable
  3. Then sudo update-rc.d startup.sh defaults as I understand it, to register the script to run at startup.

(These instructions were pulled straight from the page I linked above. I don't at all have a thorough understanding of what they actually do. I'm just following the best directions I can find.)

I have tested the raspistill command that I used in the script, and I know that it does work, and saves a timestamped image to the designated folder. I can even run the script from the init.d folder (by double-clicking on it in the GUI) and it works from that location when I run it. One last thing to note here, is that it does ask me what I'd like to do when I double click it, giving the options: Execute, Execute in Terminal, Open, and Cancel. I don't know if that's relevant to my issue, but I want to get everything out there.

Can someone please help me figure out what I'm doing wrong? TIA!

  • The INIT info section at the beginning of my script, was also pulled directly from the linked page (and then I replaced my script name and location with the one in the example.)
    – Ronthebear
    Nov 13, 2018 at 20:50
  • What operating system are you using? Is it Raspbian Stretch?
    – Ingo
    Nov 14, 2018 at 19:12
  • Yes, Raspberrian Stretch installed via NOOBS method.
    – Ronthebear
    Nov 16, 2018 at 13:20

2 Answers 2


You should have better used method 4: systemd from the linked page. systemd is the default init system and all others is only emulated by it with known limitations: Compatibility with SysV. Because your program runs from the command line I would use a systemd unit. Before doing it you should revert things you have done with init.d. Then create a new service with:

rpi ~$ sudo systemctl edit --force --full raspistill.service

In the empty editor insert these statements. You have to replace /absolute/path/to/ with the real one. Save this and quit the editor.

Description=Raspistill service

ExecStart=/absolute/path/to/raspistill --annotate 12 -o /home/pi/Pictures/Startup/Startup_`/bin/date +%d%m%Y_%H%M-%S`.jpg


Then enable the new service and reboot:

rpi ~$ sudo systemctl enable raspistill.service
rpi ~$ sudo systemctl reboot

Check with:

rpi ~$ systemctl status raspistill.service
rpi ~$ journalctl -b -e
  • Awesome, thanks for the help. I’ve been busy and haven’t gotten back to this to try it yet, but I wanted to say thanks!
    – Ronthebear
    Nov 29, 2018 at 20:59
  • @Ronthebear I'm not sure if I met all edge conditions because lack of information. Tell me if it does not work. There are many options for the environment to make it run (man systemd.exec).
    – Ingo
    Nov 30, 2018 at 0:05
  • I've been trying to run a time lapse using picam on startup. The systemd method from the linked webpage is the only method that works, out of four that I tried. Thanks!
    – smcs
    Jul 15, 2021 at 10:18

so I'm guessing that the problem is with the script

I am no so sure it is your script that is the main issue.

Both init.d and systemd are responsible for loading and running services on a Linux derivative like raspbian. Systemd replaced init.d as the method to start hardware and software services, so Ingo (see below) is correct that systemd is to be preferred.

A issue I have encountered with starting services on a RPI is that it boots much faster than a conventional server, so quite often it has run through the startup services sequence before the hardware has fully initialised.
So it may be your script is running, but the camera is not ready. I have solved this in my use case by putting the command in a script and including a sleep to allow the hardware to catch up.

Save this file as: /usr/local/bin/startupstill

sleep 30
/absolute/path/to/raspistill --annotate 12 -o /home/pi/Pictures/Startup/Startup_`/bin/date +%d%m%Y_%H%M-%S`.jpg

Run the following commands, to ensure the file ownership is correct and it is executable:

chown pi:pi /usr/local/bin/startupstill

chmod u+x /usr/local/bin/startupstill

Then in Ingo's example systemd service script use Type=forking in the [Service] section, then change the following lines:




  • 1
    Please never send a service to the background by job control with & within a systemd service. This way systemd looses any control about the daemon. Programs started with systemd are already made a service. If you want the behavior of traditional UNIX daemons you must use Type=forking in the [Service] section. You should correct your answer.
    – Ingo
    Mar 8, 2019 at 16:39
  • Happy to learn a better approach. The purpose of the approach was to stop the whole boot process hanging while the sleep ran down and defeating the purpose of the sleep of allowing the rest of the system to come up. Revised my solution with your proposal.
    – Falstone
    Mar 11, 2019 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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