How to make sure a ipk process always running?

using cron like https://stackoverflow.com/questions/298760/how-to-make-sure-an-application-keeps-running-on-linux ?

is it a good method?
another question: how to make crond start up after boot by change configure file?

cron is for scheduling jobs.

having them run constantly is achieved by adding & at the end of the command line,
or setting it up as a service.

crond will start on boot, since it's the scheduler, but you can start/restart it manually through the webUI.

1 Like

crond will start on boot if there is one task or more in the list. Cron is good for running commands that have an end, for example run a backup script on a schedule.

To keep a service running you should make a service, so an init script for it https://openwrt.org/docs/techref/initscripts
possibly one using procd functionality https://openwrt.org/docs/guide-developer/procd-init-script-example because procd is able to track the service status and restart it if crashes

default cron is not enable

cron will enable if you add at least a task in the list

now im using the service like below

#!/bin/sh /etc/rc.common
# "new(er)" style init script
# Look at /lib/functions/service.sh on a running system for explanations of what other SERVICE_
# options you can use, and when you might want them.
 
START=80
APP=mrelay
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
 
start() {
        service_start /usr/bin/$APP
}
 
stop() {
        service_stop /usr/bin/$APP
}

so system help me do restart the ipk app if it is crashed?

no, because that is a normal service. Normal service only starts and stops with system.

If you want restart if crashed you should make initscript that uses procd https://openwrt.org/docs/guide-developer/procd-init-script-example
and use the "respawn" option from "advanced options" paragraph

3 Likes

how does it work and does it monitor the pid?

it will monitor the process you write in
procd_set_param command /bin/myapp

because procd is running that command and the process will then become its child process.

So you must write there the actual application, so for example /bin/myapp above not a script that launches it and then quits

I do not know how this works, there is little documentation about how procd actually does this job. You can look at the source code. https://git.openwrt.org/?p=project/procd.git;a=tree

1 Like

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