# Running background job from pkg POST-INSTALL script



## Xylene (Apr 11, 2018)

I have a binary package that in it's post-install script starts a backgroup job. (Mimics a daemon) Currently when executing pkg install <package> the post-install script is ran and the background job is started, but upon exit of pkg, pkg also kills all of its children including the background job.  I am trying to figure out a way to ether get pkg to no kill all children on exit, or to run the background job in its own process group.


----------



## SirDice (Apr 11, 2018)

Xylene said:


> I have a binary package that in it's post-install script starts a backgroup job.


This is generally frowned upon. Personally I do not like the idea of a package that "automagically" starts its own (background) processes. 


Xylene said:


> (Mimics a daemon)


These should be started using rc(8) scripts. And the general rule of services/daemons is that they're off by default and need to be specifically enabled.


----------



## Xylene (Apr 11, 2018)

SirDice said:


> This is generally frowned upon. Personally I do not like the idea of a package that "automagically" starts its own (background) processes.
> 
> These should be started using rc(8) scripts. And the general rule of services/daemons is that they're off by default and need to be specifically enabled.



This is wrapped in an rc script that is installed at /etc/rc.d. In my particular test case the package is already installed and running and this is an upgrade. After the upgrade is over the install restarts the "daemon" by invoking service <daemon> restart in the post-install section of the installer. (Seems like standard practices to me)

The daemon is restarted and running, but as soon as the pkg installer exits the daemon is killed.


----------



## SirDice (Apr 11, 2018)

Xylene said:


> This is wrapped in an rc script that is installed at /etc/rc.d.


Wrong place. It should be /usr/local/etc/rc.d. 



Xylene said:


> In my particular test case the package is already installed and running and this is an upgrade. After the upgrade is over the install restarts the "daemon" by invoking service <daemon> restart in the post-install section of the installer. (Seems like standard practices to me)


Not on FreeBSD. No port/package (of the 33701 available) automatically restarts (or starts) services.


----------

