Opkg - do not enable the service

I designed very simple .init file to start app as a service. It starts after installed with opkg. Great.

Is there any way to keep service disabled (no entry in /etc/rc.d/S*) for the service after installing with opkg? Tried "autoenable=no" and "autoenable=false", none of these help.

Second question, which was already asked somewhere, but I do not see definite answer or answer does not work :frowning: -- if I flash the whole OS image to the device, is there any way to keep service disabled after image is installed?

The goal here - service must be enabled and ready to start/respawn after it gets configured, not earlier (e.g. immediately after opkg of image flashing).

Disable it in postinst, or ship a config with option enabled set to 0 and have your init script handle that.

1 Like

Disabled in the postinst, but opkg (or system?) anyway starts application as a service calling start_service() after completion of the postinst script.

It seems package is being re-enabled after I disable it in the postinst script.

And it also looks like (using strace) that daemon is being launched (using start_service) in parallel to postinst script just after files were written onto their locations, and that's why disabling service in the postinst has no effect.

Removal also seems to work incorrectly: if application runs as a service, but was disabled, opkg remove does not stop running application. I had stupid exit 0; at the end of postinst script, which terminated further processing :frowning:

Anyway, when I perform opkg remove with service stopped, it says 'Command failed: Not found' as it seems trying stopping already stopped service. Same issue stopping already stopped service... while I guess there's a way to know that service is not running and state that there's nothing to stop.

Update: seems have solved 'Command failed: Not found' issue:

	if [ ! "$r" = "0" ]; then { echo "Stopping application service"; service_stop $DIR/$PROG; } else { echo "application is not running"; } fi

changed to

	if [ ! "$r" = "0" ]; then { echo "Stopping application service"; } else { echo "application is not running"; exit 0; } fi
  • it appeared that I do not need to run service_stop() in my script;
  • and must perform forceful exit 0 if do not see process with respective name running (preventing start-stop-daemon from stopping inexistent process).
  • "$r" here is flag of process running or not.