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

    Run script on shutdown

    Development
    2
    3
    2.1k
    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.
    • Z
      Zorac
      last edited by

      ive created a package, but need a script to run on shutdown.

      right now i have a package.sh file in /usr/local/etc/rc.d/ which runs fine on startup (with start), but the stop function doesn't run on shutdown(ie /usr/local/etc/rc.d/package.sh stop).  my package name matches the sh file name, and i have tried the <rcfile>tags in the config for the package, as well as a number of other combinations.  google and site search give me some direction, but i still can't get it to work.  any suggestions would be appreciated.

      thanks.</rcfile>

      1 Reply Last reply Reply Quote 0
      • P
        phil.davis
        last edited by

        pkg-utils.inc stop_packages() loops through each package name and calls stop_service for that package
        (assuming the package name and service name are the same - on 2.1 you can specify an internal name for a package if the package name does not match the service name - e.g squid3 internal name is squid)
        It remembers which services it has already stopped. For those, it does not call a matching *.sh file later - e.g. /usr/local/etc/rc.d/squid.sh will not get called, because stop_service("squid") has already been done.
        The problem comes if your "package.sh stop" code needs to do more than what stop_service() already did - perhaps save some data, kill some other processes… With the current package system, you need to make another script with a different name "/usr/local/etc/rc.d/package-extras.sh" that takes the "start" and "stop" parameters and does any extra stuff at startup and shutdown - e.g. look in squid3 (squid-reverse in GitHub) squid.inc for sqp_monitor.sh

        As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
        If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

        1 Reply Last reply Reply Quote 0
        • Z
          Zorac
          last edited by

          thanks, that put me in the right direction.

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