Adding a script file into OpenWrt package & Run in init.d

Hi Friends,

I'm trying to add my Script file (Cstats.sh) into Collectd package. Also I want this script file (Cstats.sh) to be run always like other processes in AP. I've added Cstats.sh script file into collectd package and build the source code. After flashing my image into AP, I couldn't see my script file in AP.

Till now, manually added my script file in AP and that is working fine. Now I want to add that Script file into Collectd package. Please support me to add a Script file into my collectd package.

I know that we can add files in root directory e.g. "RootFolder/files/etc/config/collectd.sh" and "RootFolder/files/etc/init.d/collectd". But, I want to add script file into my collectd package itself and also want that to run like other processes, Atleast i need this script file to be placed in some folder.

My Package location in source code: sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd

$ls sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd

files     Makefile    patches

files --> collectd.conf   ==> This file contains collectd specific configuration (It's available under /etc/conf/collectd.conf in AP)

files --> collectd.init

collectd.init
================
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org

START=80

SERVICE_USE_PID=1

start() {
	mkdir -m 0755 -p /var/lib/collectd
	service_start /usr/sbin/collectd
	mkdir -m 0755 -p /etc/Cstats.sh    	==> my script file
	service_start /etc/Cstats.sh          ==> my script file
}

stop() {
	service_stop /usr/sbin/collectd
}


Makefile
================

............................
............................

define Package/collectd/conffiles
/etc/collectd.conf
/etc/Cstats.sh                               ==> My script file
endef

define Package/collectd/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/collectd $(1)/usr/sbin/
        $(INSTALL_DIR) $(1)/usr/share/collectd
        $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/collectd/types.db $(1)/usr/share/collectd/
        $(INSTALL_DIR) $(1)/etc
        $(INSTALL_CONF) ./files/collectd.conf $(1)/etc/
        $(INSTALL_DIR) $(1)/etc
        $(INSTALL_CONF) ./files/etc/Cstats.sh $(1)/etc/
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/collectd.init $(1)/etc/init.d/collectd
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/collectd.init $(1)/etc/Cstats.sh
endef

...........................
...........................

Link to collectd package in opewrt: https://github.com/openwrt/packages/tree/openwrt-18.06/utils/collectd

Please support me to add my script file into collectd package and make it available in AP. Thanks.

If you want to change a package Makefile locally, you can branch the git feed (from its directory) and build from source (the image builder uses pre-built packages). You’d probably want to rebase your changes after pulling any upstream package-feed changes.

1 Like

Thanks Jeff. I understand that it is not possible to change collectd package directly. If i want to do any changes, i have to pull the source code of collectd and add it into my openwrt code. Also I need to change the code to take changes from collectd source instead of pre-build package.

is that my understanding correct jeff?

This needs to be:

$(INSTALL_DIR) $(1)/etc
$(INSTALL_BIN) ./files/Cstats.sh $(1)/etc/Cstats.sh

Drop your Cstats.sh into the files/ sub-folder of the collectd package before compiling.

Also, you do NOT need:

/etc/Cstats.sh ==> My script file

2 Likes

Thank you @stangri. I'll check your solution and come back. Thanks.

Hi @stangri, Sorry It is not working. Am i doing any mistake, please check my files changes. Thanks.

wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd$ ls
files  Makefile  patches
wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd$ 

wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd$ ls files/
collectd.conf  collectd.init  Cstats.sh
wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk/package/feeds/packages/collectd$ 

Makefile
==============

define Package/collectd/conffiles
/etc/collectd.conf
endef

define Package/collectd/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/collectd $(1)/usr/sbin/
	$(INSTALL_DIR) $(1)/usr/share/collectd
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/collectd/types.db $(1)/usr/share/collectd/
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_CONF) ./files/collectd.conf $(1)/etc/
#==> my change - start
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_BIN) ./files/Cstats.sh $(1)/etc/Cstats.sh
#==> my change - end
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/collectd.init $(1)/etc/init.d/collectd
endef


Elaborate.

I have done changes and build successfully. But my script file is not available in AP in /etc folder or any other folder after flashed image.

do i need to add the below changes also in my package?

collectd.init
================
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org

START=80

SERVICE_USE_PID=1

start() {
	mkdir -m 0755 -p /var/lib/collectd
	service_start /usr/sbin/collectd
====> Removed	mkdir -m 0755 -p /etc/Cstats.sh  bcz it is not directory <===
	service_start /etc/Cstats.sh          ==> my script file
}

stop() {
	service_stop /usr/sbin/collectd
}

Can you post the package you've built?

Output of ls /etc/Cstats.sh?

Found following in build directory

wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk$ find * -name Cstats.sh
build_dir/target-arm_cortex-a7_uClibc-1.0.14_eabi/collectd-5.4.2/ipkg-ipq806x/collectd/etc/Cstats.sh
build_dir/target-arm_cortex-a7_uClibc-1.0.14_eabi/root-ipq806x/etc/wlanstats.sh
qca/feeds/packages/utils/collectd/files/Cstats.sh
staging_dir/target-arm_cortex-a7_uClibc-1.0.14_eabi/root-ipq806x/etc/Cstats.sh
wlc@wlc-ThinkCentre-M73:~/sercom_data/ipq4019-ilq-6-1-1-1_qca_oem.git/qsdk$

AP Output

root@OpenWrt:/# find / -name collectd.conf
/etc/collectd.conf
/overlay/upper/etc/collectd.conf
/rom/etc/collectd.conf
/tmp/etc/collectd.conf
root@OpenWrt:/# find / -name Cstats.sh
root@OpenWrt:/#

Did you do make clean?

Another thing to try would be not changing the package content in feeds, I'd git-clone/copy collectd sources to package/collectd, then make changes and then build it.

1 Like

Nice. But, if i do make clean in my source code that won't work again. It is existing code issue/bug in our code :slight_smile: . Currently i've copied a new openwrt source code and trying the same method what you said as well as creating script file in root directory.

As you said, I will try to clone collectd sources from github and make the changes then try to build the same. Thanks @stangri I will try and update you soon.

Just a note to be aware of, QSDK, while based on an old version of OpenWrt, is not OpenWrt. Qualcomm/Atheros apparently has modified it significantly from its OpenWrt sources. While some of what would be suggested for OpenWrt seems to work, you may have to adjust based on that build system.

1 Like

Thanks @stangri @jeff for your valuable time and suggestions. It is working fine for me after changed files in new source code/repository. I mean, I could add script file into collectd package itself under "files" folder and able to view the same in AP device.

I didn't do anything extra other than what we discussed here. I just added my script file in "files" folder of collectd package and done changes in collectd Makefile as stated above. :slight_smile:

1 Like

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