Node APIs for turning a crontab into a data store. Create, edit, delete and pause cron jobs using only the native crontab. These APIs leverage a currently forked version of node-crontab for access to the tab.
Initialize the node_modules
directory with npm install
.
Run npm run watch:server
in the application root to watch the development folder. The output is minified to server.js
in the application root.
You can start the server with a certain user or as root to be able to access all users' crontabs. There is start_server
script included if you are running this outside of pm2.
$ sudo ./start_server
[sudo] password for kyle:
app info CronBuddy Server Running
app info Cron User: kyle
app info Node User: root
app info Port: 9191
app info IP: 127.0.0.1
Load Jobs
Method GET
Request:
/api/load // All active jobs
/api/load?type=paused // All paused jobs
Response:
{
"jobs": [
{
"action": "ls -l",
"timing": {
"fullString": "0 12 * * *",
"values": {
"dow": "0",
"month": "12",
"dom": "*",
"hour": "*",
"minute": "*"
}
}
}
]
}
Create Job
Method POST
Request:
/api/create
Params:
{
"action": "ls -l",
"timing": "0 12 * * *"
}
Response:
{
"message": "Job successfully created",
"success": true
}
Delete Job
Method POST
Request:
/api/edit
Params:
{
"action": "ls -l",
"timing": "0 11 * * *"
}
Response:
{
"message": "Job successfully edited",
"success": true
}
Pause Job
Method POST
Request:
/api/pause
Params:
{
"action": "ls -l"
}
Response:
{
"message": "Contab successfully updated",
"success": true
}
Note: Short of commenting out a line, there isn't a way to pause a job in the crontab. This API prepends the command with a #paused
comment to track its state.
The recommended way is to create a configuration file at app/config.js
. This contains your chosen port and crontab user.
Example config:
module.exports = {
PORT: 9191, // Default if no config created
USER: 'root' // Default if no config created
};
You can also override some of the configurations with the command line:
node server.js
-p=8181 // Specify the port for node server
-u=myUser // Specify which user's crontab to invoke, default `whoami`
-i=127.0.0.1 // Override the local IP