cPanel Hooks or special configs for specific actions

RyanBVI

Member
Sep 4, 2015
8
0
1
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
 

DavidN.

Active Member
Mar 19, 2013
42
3
83
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
 
Last edited by a moderator:
  • Like
Reactions: RyanBVI

RyanBVI

Member
Sep 4, 2015
8
0
1
BVI
cPanel Access Level
Root Administrator
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


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.
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
  • Like
Reactions: RyanBVI

RyanBVI

Member
Sep 4, 2015
8
0
1
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 !!!
 

RyanBVI

Member
Sep 4, 2015
8
0
1
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 !!!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
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.
 

DavidN.

Active Member
Mar 19, 2013
42
3
83
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
 

RyanBVI

Member
Sep 4, 2015
8
0
1
BVI
cPanel Access Level
Root Administrator
Ryan, if you're in need of a step-by-step look at how to implement hooks, this tutorial might also be helpful: https://documentation.cpanel.net/display/SDK/Tutorial+-+Create+a+Standardized+Hook
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 !
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
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 ???
Yes, for example you can utilize a simple .sh file that runs specific commands.

Notice: I have seen that there is also a post-upcp action running regarding CloudLinux,
my script should execute AFTER this is also completed.
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.