Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Why is service killed after package installation

    Scheduled Pinned Locked Moved Development
    6 Posts 4 Posters 1.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • artooroA
      artooro
      last edited by

      My package creates a service and an RC file for pfSense using write_rcfile and on a reboot the service starts just fine. But there doesn't seem to be anything I can do to make the service start immediately after installation.

      I've tried adding code to the custom_php_install_command that starts the service and it works, I see the service start, but then as soon as the package reaches the stage:

      Menu items... done.
      Services... done.
      Writing configuration... done.
      

      The service dies. And there are no post tasks that I can take advantage of.

      Is there a reason for this behavior? Do I have to tell users to reboot after upgrading or installing the package?

      1 Reply Last reply Reply Quote 0
      • BBcan177B
        BBcan177 Moderator
        last edited by

        You probably need to start the service… Review the file  /etc/inc/service-utils.inc  for the service commands:

        Partial List:

        /etc/inc/service-utils.inc:107:function start_service($name) {
        /etc/inc/service-utils.inc:135:function stop_service($name) {
        /etc/inc/service-utils.inc:167:function restart_service($name) {
        /etc/inc/service-utils.inc:207:function restart_service_if_running($service) {
        /etc/inc/service-utils.inc:215:function is_service_enabled($service_name) {
        /etc/inc/service-utils.inc:230:function is_service_running($service, $ps = "") {

        "Experience is something you don't get until just after you need it."

        Website: http://pfBlockerNG.com
        Twitter: @BBcan177  #pfBlockerNG
        Reddit: https://www.reddit.com/r/pfBlockerNG/new/

        1 Reply Last reply Reply Quote 0
        • artooroA
          artooro
          last edited by

          Thanks for the reply BBcan177.
          I actually do already include service-utils.inc, and at the end of my custom_php_install_command I start the service… and it starts for a couple seconds. And then as soon as the final stuff is done, it seems like when it says "Writing configuration..." that the service is killed. (I've read through the code that handles that but haven't found what causes this to happen)

          I've tested this with other packages as well. If I make changes to the unbound configuration in a custom_php_install_command it will actually kill the unbound and dhcpd service at the very end of the install after the custom command hooks are run.

          For initial installations this is not such a big issue, as then generally the user has to go to the web GUI and enable it anyway. But the big issue is for upgrades. If the user is upgrading the package I don't want them to have to reboot the entire system every time. And my understanding this was supposed to be a feature of pfSense 2.3 as demoed in the last small update.

          1 Reply Last reply Reply Quote 0
          • artooroA
            artooro
            last edited by

            For the record, I solved this by doing things the pfSense way instead of the freebsd way.
            So instead of using rc.d I wrote a shell script using write_rcfile() and it's working fine that way.
            My purist mindset wanted to stray as little from core freebsd as possible but I guess that's not quite possible yet.

            Thanks.

            1 Reply Last reply Reply Quote 0
            • D
              djmarcin
              last edited by

              I'm already using write_rcfile and restart_service in my package and every time I do 'pkg install' or 'pkg upgrade' it's killed post-installation.

              It does appear to restart.  If I insert sleeps through the code I can see a new PID but after it completes the new PID is killed.  I've traced the code to /etc/rc.packages but everything seems fine just before that code exits.

              'ps aux -d' seems to shed some light – when the service starts it appears to fork but becomes attached to the 'pkg upgrade' command not init, so when pkg exits, so does the service itself.

              This seems to either be a bug with pfSense or with the service itself not daemonizing properly.

              1 Reply Last reply Reply Quote 0
              • D
                doktornotor Banned
                last edited by

                Service is killed normally as part of uninstall, see function uninstall_package() in pkg-utils.inc

                I'm completely confused with the daemonize stuff or whatever you mention, pretty sure that's not the problem. Put some log_error() stuff in place (or use /usr/bin/logger in the .sh script) and see how many times the service is (re)started on reinstall.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.