I have an IoT device with a barebones Linux distro on it. No crontab, chkconfig, or update-rc.

How would I go about running a script when the device has started, after everything on the device has been loaded? I thought I could just add the script to /etc/init.d but nothing seems to happen. This is the script I'm using.

#! /bin/sh -e
# /etc/init.d/camstart

. /etc/init.d/functions.sh

start() {

stop() {
    kill `pidof myapp`
    kill `pidof myappinternal`

case "$1" in
        pidof myapp
        pidof myappinternal
        echo "Usage: $0 {start|stop|status|restart}"

exit 0

My other idea was to use /etc/rc.local, but the device does not have that file. It has rc?.d folders ranging from 1-6 and S. Placing scripts in any of them doesn't seem to have any affect.

Any suggestions?

EDIT: I'm not sure what Linux distro it is, but checking /etc/*release tells me that it is based on Poky from the Yocto Project. From /proc/version it's Linux version 4.9.62.

As far as I can tell, it uses systemctl to start systemd services.

EDIT2: Forgot to mention. I've tried writing a systemd service for my script and starting it using systemctl start app but it exits immediately with exit code 0.



ExecStart=/etc/init.d/app start
ExecStop=/etc/init.d/app stop

FINAL EDIT: Got it to work after looking at How to write startup script for systemd and saw that my systemd service was missing

  • 3
    As you can see, answerers are going to adopt your unwarranted assumption that you even have van Smoorenburg init+rc on that system. Find out what softwares actually do perform startup and shutdown, which could be anything from BusyBox init to runit, and tell answerers that in the question. Or tell answerers what the operating system actually is, rather than a vague and unhelpful "Linux distribution", and thereby enable them to try to find out for themselves.
    – JdeBP
    Jun 20 '18 at 13:42
  • Do you have a desktop on your system or is it headless ?
    – Kiwy
    Jun 20 '18 at 14:14
  • Headless. Only have a terminal via ssh. Jun 20 '18 at 14:16
  • did you read this question/answer unix.stackexchange.com/q/47695/53092
    – Kiwy
    Jun 20 '18 at 14:29

The procedure to start automatically a daemon in runlevel 3 is easy:

  1. place your script in /etc/init.d,
  2. check permissions and ownership of the script,
  3. create a symbolic link in /etc/rc3.d to the script with the following name S99scriptmame.

The S means start the service. The number is used to sort the service start order from 01 (high priority script) to 99 (last priority script).

Probably, do you need to create a link to the script in /etc/rc0.d (halt) and /etc/rc6.d (reboot) named K01scriptname. Usually last started deamon is the first to be stopped.

See man init.d^1 for a complete explanation.

  • There is no /etc/rc.d. Should I just make one? Jun 20 '18 at 13:41
  • Ops, sorry. I fixed the dir name.
    – andcoz
    Jun 20 '18 at 14:07
  • Does not work, unfortunately. Jun 20 '18 at 14:32
  • Use runlevel command to check current run level. Is it N 3?
    – andcoz
    Jun 20 '18 at 15:04
  • It just says unknown Jun 25 '18 at 7:30

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.