Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:guide-developer:procd-init-script-example [2019/03/13 05:28] – [Setting up] now with a btetter shell script bobafetthotmaildocs:guide-developer:procd-init-script-example [2024/02/10 17:38] (current) – [Enabling the service] systemcrash
Line 1: Line 1:
-====== Service configuration with procd======+====== Create a sample procd init script======
 <WRAP center round info 80%> <WRAP center round info 80%>
-This article is a mostly verbatim copy of https://joostoostdijk.com/posts/service-configuration-with-procd/ any credit goes to the original author, **Joost Oostdijk** \\ +This article is a mostly verbatim copy of [[https://web.archive.org/web/20220518121856/https://joostoostdijk.com/posts/service-configuration-with-procd|this archived article]], all credit goes to the original author, **Joost Oostdijk** \\ 
-It was adapted to use an equivalent shell script instead of a node javascript, because it's lighter and better for a simple testing setup on most OpenWrt devices.+It was adapted to use an equivalent shell script instead of NodeJS JavaScript, because it's lighter and better for a simple testing setup on most OpenWrt devices.
 </WRAP> </WRAP>
  
Line 19: Line 19:
  
 if [ "$1" = '' ]; then if [ "$1" = '' ]; then
-   name="You"+    name="You"
 else else
-    if   echo "$1" | egrep -q '^[0-9]+$'  ; then+    if echo "$1" | egrep -q '^[0-9]+$'; then
         name="You"         name="You"
     else     else
-    name="$1"+        name="$1"
     fi     fi
 fi fi
  
 if [ "$2" = '' ]; then if [ "$2" = '' ]; then
-   every="5"+    every="5"
 else else
-   every="$2"+    every="$2"
 fi fi
  
-if   echo "$1" | egrep -q '^[0-9]+$'  ; then +if echo "$1" | egrep -q '^[0-9]+$'; then 
-        every="$1"+    every="$1"
 fi fi
  
Line 41: Line 41:
  
 while [ 1 ]; do  while [ 1 ]; do 
-   echo "Hey, $name, it's time to get up" +    echo "Hey, $name, it's time to get up" 
-   sleep $every+    sleep $every
 done done
  
Line 81: Line 81:
 <code> /etc/init.d/myservice enable</code> <code> /etc/init.d/myservice enable</code>
  
-This will install a symlink for us in directory /etc/rc.d/ called S90myservice which point to our respective service script in /etc/init.d/. OpenWrt will start the services according the the order of S* scripts in /etc/rc.d/. To see the order you could simply run+This will install a symlink for us in directory /etc/rc.d/ called S95myservice (because ''START=95''which points to our respective service script in /etc/init.d/. OpenWrt will start the services according the the order of S* scripts in /etc/rc.d/. To see the order you could simply run
  
 <code>$ ls -la /etc/rc.d/S*</code> <code>$ ls -la /etc/rc.d/S*</code>
Line 154: Line 154:
  
 <code>$ uci show myservice <code>$ uci show myservice
-mynodeservice.hello=myservice +myservice.hello=myservice 
-mynodeservice.hello.name=Joost +myservice.hello.name=Joost 
-mynodeservice.hello.every='5'+myservice.hello.every='5'
 </code> </code>
 Also single options can be requested Also single options can be requested
Line 216: Line 216:
 ...</code> ...</code>
  
-With that line in place we are able to only restart the service whenever our configuration has changed.+With that line in place we are able to restart the service whenever only our configuration has changed.
  
 <code>$ /etc/init.d/myservice reload <code>$ /etc/init.d/myservice reload
Line 226: Line 226:
 I’ll list a few here, but this is by no means covering everything. I’ll list a few here, but this is by no means covering everything.
  
-  * **respawn**\\ respawn your service automatically when it died for some reason.\\ <code bash>procd_set_param respawn \+  * **respawn**\\ respawn your service automatically when it terminates for some reason.\\ <code bash>procd_set_param respawn \
       ${respawn_threshold:-3600} \       ${respawn_threshold:-3600} \
-      ${respawn_timeout:-5} ${respawn_retry:-5}</code> \\ In this example we respawn if process dies sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped+      ${respawn_timeout:-5} ${respawn_retry:-5}</code> \\ In this example we respawn if process terminates sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped. However, if it terminates later than respawn_threshold, it would be respawned indefinitely.
  
   * **pidfile**\\ Configure where to store the pid file \\ <code bash>procd_set_param pidfile $PIDFILE</code>   * **pidfile**\\ Configure where to store the pid file \\ <code bash>procd_set_param pidfile $PIDFILE</code>
  • Last modified: 2019/03/13 05:28
  • by bobafetthotmail