The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel Hooks or special configs for specific actions

Discussion in 'cPanel Developers' started by RyanBVI, Sep 4, 2015.

  1. RyanBVI

    RyanBVI Member

    Joined:
    Sep 4, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    BVI
    cPanel Access Level:
    Root Administrator
    Hello,

    I need to perform specific actions before and after a cPanel server does scheduled tasks,
    like the daily backups and the update of the system...

    I am using the new backup system / daemon and the stable tier for updates and
    have scheduled these services through WHM crons scheduler to execute:
    update @ 1:00 AM
    backup @ 2:00 AM


    I know I could just put a cron to perform the tasks I need, just few mins before
    these times, but there is no easy way to detect when / if they finished,
    so I was wondering, if there is another way, to be able to configure an .sh
    script or command, to be executed, before and after these services run...


    Any ideas and insight will be highly appreciated !


    Thanks,
    Ryan
     
  2. cPDavidN

    cPDavidN cPanel Developer
    Staff Member

    Joined:
    Mar 19, 2013
    Messages:
    42
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    DataCenter Provider
    Hi Ryan,

    Thanks for the question! cPanel has standardized hook points that execute before and after system backups run. There are also hook points that run before, during, and after each individual account backup, if you need finer-grained control. It sounds like these are the hook points you'll need:

    https://documentation.cpanel.net/display/SDK/Guide+to+Standardized+Hooks+-+System+Functions

    The "Guide to Standardized Hooks" in the SDK should have all the information you need to adapt cPanel to your use case, but if you have more, you can reply here, or email integrationATcpanel.net to open a support ticket. And if you're coming to cPanel conference, I'll be there and can answer questions in person.

    Thanks!

    David Nielson
    Integration Developer, cPanel
     
    #2 cPDavidN, Sep 4, 2015
    Last edited by a moderator: Oct 7, 2015
    RyanBVI likes this.
  3. RyanBVI

    RyanBVI Member

    Joined:
    Sep 4, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    BVI
    cPanel Access Level:
    Root Administrator


    Thank you David for your reply and help with this.

    It seems that backup system does actually already have an advanced method to satisfy all my needs,
    I checked the SDK and it's pretty much straight-forward for my needs...

    Do you have any suggestion also regarding the update system ("upcp" scheduled daemon) ???


    Thanks again, waiting for your news regarding upcp.
     
    #3 RyanBVI, Sep 4, 2015
    Last edited by a moderator: Oct 7, 2015
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,707
    Likes Received:
    658
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Yes, upcp is the first function listed at:

    Guide to Standardized Hooks - System Functions

    Is that what you are looking for?

    Thank you.
     
    RyanBVI likes this.
  5. RyanBVI

    RyanBVI Member

    Joined:
    Sep 4, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    BVI
    cPanel Access Level:
    Root Administrator
    Hello,

    yes, this seems to be what I am looking for, but still, I am unable to find how to achieve my task...

    Is there any real-life example, how I can actually implement these things ???


    For example, let's say, I want to execute the following scripts:

    /usr/local/src/custom/updates/before.sh
    /usr/local/src/custom/updates/after.sh
    /usr/local/src/custom/backups/before.sh
    /usr/local/src/custom/backups/after.sh


    Can you please give me a real-life example, how these 4 scripts can be set to execute,
    each at the proper time ??? (Please note that the paths and filenames are self-explaining
    of what goes where...)


    Thanks for any help in advance !!!
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,707
    Likes Received:
    658
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  7. RyanBVI

    RyanBVI Member

    Joined:
    Sep 4, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    BVI
    cPanel Access Level:
    Root Administrator
    Hello,

    I have the following scripts:

    1: /usr/local/src/custom/updates/before.sh
    2: /usr/local/src/custom/updates/after.sh
    3: /usr/local/src/custom/backups/before.sh
    4: /usr/local/src/custom/backups/after.sh


    Each script, is a bash script, tested to work in standalone / shell execution mode (already chmoded to +x).


    Can anyone help me and explain me how I can add these scripts to execute at
    the proper time via cPanel Hooks system ???

    1: should run, BEFORE cPanel updater runs (before upcp)
    2: should run, AFTER cPanel updater completes (after upcp)
    3: should run, BEFORE cPanel new backups runs (before backups)
    4: should run, AFTER cPanel new backups completes (after backups)


    Notice: I have seen that there is also a post-upcp action running regarding CloudLinux,
    my script should execute AFTER this is also completed.


    Actually, my scripts should explicitly execute before and after the cPanel daemons run.



    Thanks on advance for your help !!!
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,707
    Likes Received:
    658
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    I've merged your post into this thread. Could you let us know if the last response in the thread referenced earlier is helpful?

    Thank you.
     
  9. cPDavidN

    cPDavidN cPanel Developer
    Staff Member

    Joined:
    Mar 19, 2013
    Messages:
    42
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    DataCenter Provider
    Hi Ryan,

    To get your hook scripts to run, you'll need to register them into the hooks database with the utility /usr/local/cpanel/bin/manage_hooks. The --help output there should be enough information to get you started. If you have any more questions, please let us know. Thanks!

    David Nielson
    Integration Developer, cPanel
     
  10. cPSarah

    cPSarah Registered
    Staff Member

    Joined:
    Aug 15, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
  11. RyanBVI

    RyanBVI Member

    Joined:
    Sep 4, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    BVI
    cPanel Access Level:
    Root Administrator
    To be frank, I was looking for something less sophisticated and that did not require code to be written for the script to work ...

    All my bash scripts, contain just few file manipulation lines and I really don't need to have logs or other things, just the scripts to be executed on the proper moment ...


    Is it possible to do this, without adding any extra code in the scripts and without the need to add them on specific paths, as indicated on the example ???


    I have the following scripts:

    1: /usr/local/src/custom/updates/before.sh
    2: /usr/local/src/custom/updates/after.sh
    3: /usr/local/src/custom/backups/before.sh
    4: /usr/local/src/custom/backups/after.sh

    1: should run, BEFORE cPanel updater runs (before upcp)
    2: should run, AFTER cPanel updater completes (after upcp)
    3: should run, BEFORE cPanel new backups runs (before backups)
    4: should run, AFTER cPanel new backups completes (after backups)

    Notice: I have seen that there is also a post-upcp action running regarding CloudLinux,
    my script should execute AFTER this is also completed.


    If anyone can help me to show me for one of them, how it can be set to execute on proper time, without need to add extra code,
    I would be grateful.



    Thanks !
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,707
    Likes Received:
    658
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Yes, for example you can utilize a simple .sh file that runs specific commands.

    Yes, this is possible with the "--weight" option that's documented at:

    Guide to Standardized Hooks - The manage_hooks Utility - Software Development Kit - cPanel Documentation

    Thank you.
     
Loading...

Share This Page