I've read the following documentation (https://oldwiki.archive.openwrt.org/doc/techref/initscripts). My scope is to start a script when my OpenWrt device is rebooted. Anyway, I can't understand some things: in this guide, I can see that in the /etc/init.d folder, there are many scripts, in which there are the command start, stop, enable and so on. Instead I have a compiled C program, so when I put my program in the /etc/init.d folder, I can't write the command start(), stop() etc. to this program (not even before compiling it, because for example the directive #!/bin/sh is not recognized). So, how can I do to start automatically my compiled C program when I reboot my OpenWrt device? This program execute some generic operations, and I need that this operations are executed each time that the device is started.
Asked
Active
Viewed 163 times
0
-
1*I can't write the command start(), stop()*. You need to write a shell script that implements those commands which then starts or kills the compiled C binary. That is, the start/stop is handled by the wrapper script and not the C program itself. Take a look at the other scripts in that directory and use those as an example. – kaylum Aug 11 '21 at 08:18
-
Thanks, so if I understand correctly, I have to write a script where inside the start function (for example) I write the command that I would normally give from the terminal to start my program in C? For example, inside the start function I write "./my_c_program"? – TryToLearn Aug 11 '21 at 08:23
-
ask them : https://forum.openwrt.org/ they usually are really kind – pippo1980 Aug 11 '21 at 10:52
-
see here: https://stackoverflow.com/questions/33340659/how-to-auto-start-an-application-in-openwrt – pippo1980 Aug 11 '21 at 10:57
-
played with openwrt long time ago, think u need to figure out what kind of script u need either init.d or procd see https://openwrt.org/docs/techref/initscripts, then if your binary has not been installed as a package u need to tell the system where your binary is. Not sure here if you can just put your binary into
/files folder before compiling openwrt image and then point to that folder in your init script (not sure again file should be in etc/ folder after flashing image to your device) (of course your binary should be compiled exactly for the platform you created the image for) – pippo1980 Aug 11 '21 at 11:46 -
Not sure why you talking about #!/bin/sh in C. But in your shell script change shebang to valid line. busybox usually provides ash, `which sh` will tell you. script requires right owner/group and executable permissions – alecxs Aug 11 '21 at 15:17