OpenWrt init scripts

Hi everyone. I want to run my custom binary at the initialization of the device and run it in the background. in order to do that do I have to put the init file under

openwrt/package/mypackge-name/files/mypackage.init

will just this make it into a init program that would run at the initialization of the device.. Please tell me if my understanding is correct.

Thanks in advance

yes, you could do that... (typical package with Makefile and/or feed)... especially if your program needs to be compiled...

otherwise... you can make use of './files' to provide something like...

./files/etc/init.d/YOURPROGRAM
./files/sbin/YOURPROGRAM
1 Like

When building my program which is a basic helloworld in loop , it is omitting the files directory even when I added it to the Make file

g_dir/target-mips_34kc_uClibc-0.9.33.2/pkginfo/toolchain.default.install
WARNING: skipping libgfortran -- package not selected
WARNING: skipping ldd -- package not selected
WARNING: skipping ldconfig -- package not selected
make[2]: Leaving directory '/home/XYZ/Downloads/OPENWRT/package/libs/toolchain'
make[2]: Entering directory '/home/XYZ/Downloads/OPENWRT/package/mypackages/examples/helloworld'
mkdir -p /home/XYZ/Downloads/OPENWRT/build_dir/target-mips_34kc_uClibc-0.9.33.2/helloworld-1.0
cp /home/XYZ/Downloads/OPENWRT/package/mypackages/examples/helloworld/* /home/XYZ/Downloads/OPENWRT/build_dir/target-mips_34kc_uClibc-0.9.33.2/helloworld-1.0
cp: omitting directory '/XYZ/Downloads/OPENWRT/package/mypackages/examples/helloworld/files'
Makefile:52: recipe for target '/XYZ/Downloads/OPENWRT/build_dir/target-mips_34kc_uClibc-0.9.33.2/helloworld-1.0/.prepared_b1f1e5e0c92216459066adce95123383' failed
make[2]: *** [/home/XYZ/Downloads/OPENWRT/build_dir/target-mips_34kc_uClibc-0.9.33.2/helloworld-1.0/.prepared_b1f1e5e0c92216459066adce95123383] Error 1
make[2]: Leaving directory '/home/XYZ/Downloads/OPENWRT/package/mypackages/examples/helloworld'
package/Makefile:169: recipe for target 'package/mypackages/examples/helloworld/compile' failed
make[1]: *** [package/mypackages/examples/helloworld/compile] Error 2
make[1]: Leaving directory '/home/XYZ/Downloads/OPENWRT'
/home/XYZ/Downloads/OPENWRT/include/toplevel.mk:169: recipe for target 'package/mypackages/examples/helloworld/compile' failed
make: *** [package/mypackages/examples/helloworld/compile] Error 2

Here is the make file

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/home/XYZ/Downloads/OPENWRT/package/mypackages/examples/helloworld

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/helloworld
        SECTION:=examples
        CATEGORY:=Examples
        TITLE:=Hello, World!
endef

# Package description; a more verbose description on what our package does
define Package/helloworld/description
        A simple "Hello, world!" -application.
endef

# Package preparation instructions; create the build directory and copy the source code. 
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
        $(Build/Patch)
endef

# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
        $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
        $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/helloworld/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin

        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) files/helloworld.init $(1)/etc/init.d/helloworld
        chmod 755 $(1)/etc/init.d/helloworld
endef

# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,helloworld))
                                         

What is that I am doing wrong

they are two methods...

  1. package with Makefile (see wiki example)

OR

  1. './files' for 'premade' binaries or files (see wiki example)

are you building with a supported version?

yeah I followed to make the create the Makefile, Its the same as the one given in the example apart from the

        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) files/helloworld.init $(1)/etc/init.d/helloworld
        chmod 755 $(1)/etc/init.d/helloworld

Yeah I need uClibc so I am using chaos-calmer as the new openwrt doesnot have uClibc

I wanted to package with make file, can you tell me what am I doing wrong ??

$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/helloworld.init $(1)/etc/init.d/helloworld

chaoschalmer is no longer supported and contains several known issues...

suggest you migrate whatever you have to a supported/stable base

Can you please tell me the concept behind it when the init scripts are included and when they are not.

I honestly do not understand... it's make(file) magic...
( if the file exists... and your code is correct then they are included... there is no fancy if/not logic behind the operation )

everything i've learn't is by looking at existing examples and comparing what is common... try... make changes... try again...

for basic stuff, there is plenty of guides and reference samples to base your work on.

Okay got my issue resolved... I just had to include a -r switch with the cp to do the recursive copy which would copy the files directory and its contents and in my case that was not happening and the files directory was not getting copied.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.