OpenWrt in ProCD script-writing __openwrt

Source: Internet
Author: User
#!/bin/sh/etc/rc.common


Start=90
Stop=90
Service=app


Use_procd=1


Start_service ()

{Procd_open_instance
Procd_set_param Command/usr/sbin/app
Procd_set_param respawn
Procd_close_instance

}

Service_triggers ()
{
Procd_add_reload_trigger "Config_file_name"
}

Reload_service ()

{

}

Stop_service ()

{

}

Explain

1. Start_service () for the registration service to PROCD, if your application does not have a configuration file, as long as the implementation of Start_service (), Procd_set_param settings set many parameters, command for their own application path, Respawn can detect their own applications, if the hang off can be restarted, you can set the restart interval, other parameters can be consulted.

2. Stop_service () This is called after ProCD Kill your application, and if your application is turned off, you need some cleanup work to implement this.

3. Service_triggers () If your application needs to correlate a configuration file test, (you need to put it in the/etc/config/directory), you can track the file changes, if the file changes, call Reload_service (). You can also add a trace network modification in service_triggers, or you can track multiple profiles at the same time.

4. Reload_service () configuration file changes, you need to call this function, you can implement the function according to their own needs.

Note: The difference between start and reload is that start generally refers to application startup, reload generally refers to just reloading the part related to configuration file changes and not restarting the entire application. This approach should be recommended, and it is also possible if you restart the application in reload.


General profile file changes are judged by MD5 values,/sbin/reload_config, and the contents are as follows

#!/bin/sh

Md5file=/var/run/config.md5
[-F $MD 5FILE] && {
For C in ' Md5sum-c $MD 5FILE 2>/dev/null| grep FAILED | cut-d:-f1 '; Todo
Ubus Call Service event "{\" type\ ": \" config.change\ ", \" data\ ": {\" package\ ": \" $ (basename $c) \ "}}"
Done
}
md5sum/etc/config/* > $MD 5FILE

is to invoke the PROCD registered service event event, such as a Web page modification configuration, which is invoked via RPCD/sbin/reload_config

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.