Commit Graph

126 Commits

Author SHA1 Message Date
Girish Ramakrishnan
43e426ab9f Revert "Add no-use-before-define linter rule"
This reverts commit fdcc5d68a2.

Unfortunately, this requires us to move exports to the bottom.
This in turn causes circular dep issues and also access of
exports.GLOBAL_VAR in the global context
2025-10-08 21:17:52 +02:00
Girish Ramakrishnan
f898925bc0 tasks: update the state of crashed tasks 2025-10-08 11:16:26 +02:00
Girish Ramakrishnan
f3be7aa763 lint 2025-10-08 11:06:24 +02:00
Girish Ramakrishnan
8718e7efd2 tasks: list by prefix 2025-10-06 19:32:06 +02:00
Girish Ramakrishnan
b21d29098b tasks: refactor listByTypePaged into list with options
this way we can list by prefix (coming commit)
2025-10-06 19:28:51 +02:00
Girish Ramakrishnan
c5b7264f1a rename backupTargets to backupSites 2025-09-12 10:32:37 +02:00
Girish Ramakrishnan
19682ec21b tgz: integrity check 2025-08-15 21:23:39 +05:30
Girish Ramakrishnan
12e073e8cf use node: prefix for requires
mostly because code is being autogenerated by all the AI stuff using
this prefix. it's also used in the stack trace.
2025-08-14 12:55:35 +05:30
Girish Ramakrishnan
3aafbd2ccb backups: add backup multiple targets 2025-07-25 01:30:27 +02:00
Girish Ramakrishnan
4f608bdc5f Fix tasks test 2025-07-18 20:55:54 +02:00
Girish Ramakrishnan
48559d3358 tasks: distinguish runtime crash vs task error in worker 2025-07-18 20:02:06 +02:00
Girish Ramakrishnan
c10593e4ac tasks: remove the prefix for invokation lookup 2025-07-18 14:33:26 +02:00
Girish Ramakrishnan
0fa281083e apps: backup is not a state anymore
this is launched as a separate task
2025-07-18 14:14:54 +02:00
Girish Ramakrishnan
7047ee9391 shell: add timeout logic and rework error handling
what's important:

* if task code ran, it exits with 0. this code is regardless of (error, result)
  * when it exited cleanly, we will get the values from the database

* if task timed out, the box code kills it and it has a flag tracking timedOut. we can
  ignore exit code in this case.

* if task code was stopped, box code will send SIGTERM which ideally it will handle and end with 70.

* if task code crashed and it caught the exception, it will return 50

* if task code crashed and node nuked us, it will exit with 1

* if task code was killed with some unhandleabe signal, taskworker.sh will return the signal (9=SIGKILL)
2025-07-17 12:44:24 +02:00
Girish Ramakrishnan
5e1c32b606 shell: rename signal to abortSignal
this prevents accidental typos with child_process signal handling
2025-07-17 09:50:43 +02:00
Girish Ramakrishnan
38032f0b77 remove the ignored debug 2025-07-17 09:47:26 +02:00
Girish Ramakrishnan
c796e724aa shell/task: better logs 2025-07-17 02:04:50 +02:00
Girish Ramakrishnan
63053f46a8 shell: remove sudoCallback 2025-07-17 01:54:39 +02:00
Girish Ramakrishnan
aa0c186c8c logStream is not used anymore 2025-07-17 00:37:29 +02:00
Girish Ramakrishnan
5539f74bea system: add disk usage task 2025-07-17 00:09:50 +02:00
Girish Ramakrishnan
989d843fcb shell: make shell.sudo promise based and waitable 2025-07-16 22:04:24 +02:00
Girish Ramakrishnan
32d07e7959 add spurious log 2025-07-16 21:37:30 +02:00
Girish Ramakrishnan
b42be9899e tasks: add completed flag
in some cases, the tasks are setting percent to 100 and crashing later
2025-07-16 15:40:46 +02:00
Johannes Zellner
c0065765d4 Fix update UI to show progress and allow to cancel update task 2025-06-30 19:31:03 +02:00
Girish Ramakrishnan
a02e3d2ebd better log 2025-06-20 22:16:05 +02:00
Girish Ramakrishnan
2db99e7807 refactor: rename updater functions to have box in them 2025-06-20 19:04:55 +02:00
Girish Ramakrishnan
fb39aa32bb tasks: fix update failed notification
https://forum.cloudron.io/topic/13408/update-to-cloudron-8.3-error

We get a Task xx crashed with code null in the notification.

The crux of the issue is that we use KillMode=control-group. This ends
up sending SIGTERM signal to box code and all the sudo in parallel. The box
code then sees the sudo die and records the task as failed.

To fix, we switch to KillMode=mixed. This gives box code a chance to handle SIGTERM
first. It cleans out its task list and kills all the sudo.
2025-06-17 23:47:04 +02:00
Girish Ramakrishnan
ca25c6075b tasks: fix grammar and log the completion of sudo 2025-06-17 22:33:30 +02:00
Girish Ramakrishnan
d9c104613c tasks: rework the startTask API
it is now async. change was required to reset the pending flag
2025-06-17 19:32:46 +02:00
Girish Ramakrishnan
4770b32287 tasks: add pending field
this indicates if a task is scheduled. previously, we relied
on task.progress being 1
2025-06-17 17:00:21 +02:00
Girish Ramakrishnan
dd5e4adc73 replace underscore with our own
we only need like 5 simple functions
2025-02-13 14:14:34 +01:00
Girish Ramakrishnan
d456f91921 tasks: fix active status 2024-12-12 19:09:55 +01:00
Girish Ramakrishnan
a9e1d7641d shell: make require take a tag 2024-10-14 21:08:32 +02:00
Girish Ramakrishnan
d5ea99603f backups: give is a low oomScoreAdjust to not get killed 2024-07-19 13:05:09 +02:00
Girish Ramakrishnan
3dcd0975f7 test: fix various routes tests
* system/disks routes is gone
* provision routes now return 405 instead of 409 when re-setup/re-activated
2024-06-03 19:27:23 +02:00
Girish Ramakrishnan
13e62bc738 logs: use stream.destroy() instead of custom hooks 2024-02-24 17:35:37 +01:00
Girish Ramakrishnan
0e83658aa3 make sudo commands terminate properly
sudo forks and execs the program. sudo also hangs around as the parent of the program waiting on the program and also forwarding signals.
sudo does not forward signals when the originator comes from the same process group. recently, there has been a change where it will
forward signals as long as sudo or the command is not the group leader (https://www.sudo.ws/repos/sudo/rev/d1bf60eac57f)
for us, this means that calling kill from this node process doesn't work since it's in the same group (and ubuntu 22 doesn't have the above fix).
the workaround is to invoke a kill from a different process group and this is done by starting detached
another idea is: use "ps --pid cp.pid -o pid=" to get the pid of the command and then send it signal directly

see also: https://dxuuu.xyz/sudo.html
2024-02-24 16:19:07 +01:00
Girish Ramakrishnan
1ad94708b4 apps have to reconfigured in main thread
they cannot be done in the task process
2023-08-21 21:35:09 +05:30
Girish Ramakrishnan
4acbb7136a proper task name for dashboard change 2023-08-14 10:45:12 +05:30
Johannes Zellner
56e1f53890 Fix oidc tests after removing logoutRedirectUri 2023-07-28 16:47:10 +02:00
Girish Ramakrishnan
7926ff2811 test: only suppress starttask.sh output and not sudo
the remote support logic uses sudo output in tests
2023-07-13 09:13:28 +05:30
Girish Ramakrishnan
23f0eba1bd dyndns: run as a task
this lets us display logs
2023-07-08 21:21:06 +05:30
Girish Ramakrishnan
e6ba2a6e7a replace usage of _.extend with Object.assign 2023-05-25 11:45:14 +02:00
Girish Ramakrishnan
94eb7849fe tasks: return 404 if task not found
part of #826
2023-05-15 10:16:00 +02:00
Girish Ramakrishnan
c4f4f3e914 logs: use %o to format error
otherwise, they are printed as multi-line and this messes up tail+date formatting
2023-04-16 10:49:59 +02:00
Girish Ramakrishnan
603f92251e refactor tail invokation into logtail.sh 2023-03-27 11:39:34 +02:00
Girish Ramakrishnan
3b8221190d Better error mesasge 2022-11-20 18:16:16 +01:00
Girish Ramakrishnan
ca44f47af3 replace split with our own LogStream
split module is archived
2022-11-06 13:44:47 +01:00
Girish Ramakrishnan
8bc3b832e7 detect oom in tasks correctly 2022-11-02 22:39:25 +01:00
Girish Ramakrishnan
edb6ed91fe add disk usage task 2022-10-12 10:26:21 +02:00