Commit Graph

86 Commits

Author SHA1 Message Date
Girish Ramakrishnan
1a3d6e86a8 sudo: alway run in non-interactive 2025-07-24 14:42:31 +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
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
989d843fcb shell: make shell.sudo promise based and waitable 2025-07-16 22:04:24 +02:00
Girish Ramakrishnan
50b585c1dd shell: merge some options 2025-07-16 21:32:27 +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
89cfe1ef57 shell: add note 2025-06-17 15:08:32 +02:00
Girish Ramakrishnan
8f6637773b shell: add option for maxLines 2024-11-18 07:59:05 +05:30
Girish Ramakrishnan
df5ba25010 shell: add explicit bash() function 2024-10-16 10:40:17 +02:00
Girish Ramakrishnan
6c3ca9c364 shell: rework code to use shell.spawn
spawn gives out streams and we have more control over the stdout/stderr
buffers. otherwise, we have to provide a max buffer capture size to exec
2024-10-15 12:13:46 +02:00
Girish Ramakrishnan
7b648cddfd shell: direct exports not needed anymore 2024-10-15 09:26:02 +02:00
Girish Ramakrishnan
a9e1d7641d shell: make require take a tag 2024-10-14 21:08:32 +02:00
Girish Ramakrishnan
ca8695a1d3 typo 2024-10-14 18:26:16 +02:00
Girish Ramakrishnan
6361737cf4 sudo: use debug() to have provide timestamped logs
the exception is when sudo calls backupupload.js which already has timestamped
output because it uses node

an alternative idea is to maybe not use this flag at all and always parse the output.
this is a bit complicated since we have to look for a timestamp in a stream.
2024-10-14 15:38:55 +02:00
Girish Ramakrishnan
69f48ed11a apps: do not log app logs to output 2024-08-07 15:51:04 +02:00
Girish Ramakrishnan
9399040cd3 Fix log recursion
shell.sudo logs output to stdout/stderr intentionally. It is not meant
for scripts that generate much output (basically scripts/* files).

core of the issue is that none of the log commands require to use sudo.
they can just use normal tail. only app logs requires sudo because of the
logPaths directive in the manifest.
2024-07-25 17:48:58 +02:00
Girish Ramakrishnan
b6fbc46b58 Revert "Add option to not log shell subprocess stdout+stderr"
This reverts commit 51bb2d2bc2.
2024-07-25 11:53:56 +02:00
Johannes Zellner
51bb2d2bc2 Add option to not log shell subprocess stdout+stderr
When tailing the box log file this leads to logline recursion
2024-07-25 10:22:02 +02:00
Girish Ramakrishnan
b26ff08a3c shell: copy over code and signal values from cp object 2024-07-22 21:24:27 +02:00
Girish Ramakrishnan
7aec713e6c shell: fix streaming of stdout/stderr with sudo 2024-07-08 10:09:00 +02:00
Girish Ramakrishnan
60c4dd3875 sudo: add explicit captureStdout flag 2024-07-08 09:58:25 +02:00
Girish Ramakrishnan
07527fe2b1 shell: when using shell use child_process.exec
arg splitting messes up arguments and debug output
2024-02-28 18:34:07 +01:00
Girish Ramakrishnan
bcc78d81a6 shell: also print the args 2024-02-28 17:56:20 +01: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
d0dc104ede logs: make logPaths work
we have to tail via sudo script

Fixes #811
2024-02-23 17:46:22 +01:00
Girish Ramakrishnan
4ebff09f73 lint 2024-02-22 16:50:35 +01:00
Girish Ramakrishnan
e6aef755e3 shell: merge spawn into sudo 2024-02-22 12:43:23 +01:00
Girish Ramakrishnan
60994f9ed1 shell: docker run needs shell
don't want to get into parsing quotes!
2024-02-22 10:59:39 +01:00
Girish Ramakrishnan
a6f078330f shell: no need to promise scoping 2024-02-21 19:40:27 +01:00
Girish Ramakrishnan
cfd5c0f82b shell: rewrite exec to use execFile
this also renames execFile to execArgs
2024-02-21 18:54:43 +01:00
Girish Ramakrishnan
14c9260ab0 shell: exec encoding is utf8 by default and no shell
explicitly mark calls that require the shell
2024-02-21 17:47:25 +01:00
Girish Ramakrishnan
23cac99fe9 shell: remove spawn 2024-02-21 13:35:56 +01:00
Girish Ramakrishnan
2237d2bbb7 shell: remove usage of .spawn 2024-02-21 13:27:04 +01:00
Girish Ramakrishnan
c1bb4de6a3 reverseproxy: use async exec 2024-02-21 12:33:04 +01:00
Girish Ramakrishnan
9b94cf18d0 convert more execSync to async 2024-02-21 11:00:12 +01:00
Girish Ramakrishnan
b51071155a Use the async shell exec 2024-02-20 22:57:36 +01:00
Girish Ramakrishnan
26eb739b46 shell: add options to exec 2024-02-20 21:11:09 +01: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
13a8926f60 sudo: suppress starttask.sh logs in test 2023-07-13 09:01:14 +05:30
Girish Ramakrishnan
7af44e1fdd typo 2023-03-29 22:29:26 +02:00
Girish Ramakrishnan
8ef730ad9c backuptask: make upload/download async 2022-04-28 21:37:08 -07:00
Girish Ramakrishnan
7f89dfd261 add once.js 2022-04-15 19:01:35 -05:00
Girish Ramakrishnan
7709e155e0 more async'ification 2021-09-07 11:21:06 -07:00
Girish Ramakrishnan
b5d6588e3e updater: async'ify 2021-08-31 13:12:14 -07:00
Girish Ramakrishnan
03e22170da appstore and support: async'ify 2021-08-18 23:38:18 -07:00
Girish Ramakrishnan
0a3a7cb1a3 debug: replace newline in args 2021-06-18 14:33:50 -07:00
Girish Ramakrishnan
238073fe48 volume: get status 2021-05-13 16:08:55 -07:00