36 Commits

Author SHA1 Message Date
timmy b15bede430 Best practices 2026-07-12 14:12:15 -07:00
Michael Stapelberg efdb49ac88 supervise: only set $PATH if not already set
fixes https://github.com/gokrazy/gokrazy/issues/371
2026-06-01 20:09:05 +02:00
Brad Fitzpatrick ac50d95cc1 Support specifying remote_syslog target via Linux cmdline (#275) 2026-05-18 08:31:12 +02:00
Michael Stapelberg 599a48c65e supervise: set $PATH to /user:/gokrazy so that binaries can be found 2026-04-18 10:56:39 +02:00
Justin Overfelt 368604ae5a Automatically set USER to root if not already set (#322)
fixes https://github.com/gokrazy/gokrazy/issues/320

Co-authored-by: Justin Overfelt <justin@overfelt.family>
2025-07-13 11:15:50 +02:00
Michael Stapelberg b2b842e326 fix reading Go module info for diverted services
related to https://github.com/gokrazy/gokrazy/issues/189
2023-04-03 09:03:21 +02:00
Michael Stapelberg 7e14fb215c fix panic by initializing service in NewService, not supervise()
fixes https://github.com/gokrazy/gokrazy/issues/189
2023-04-03 09:00:37 +02:00
oliverpool b85b03e5bd implement Poweroff (and refactor around killSupervisedServices) (#177) 2023-03-07 20:38:36 +01:00
Michael Stapelberg e2c5a62f67 supervise: create /perm/home/<base> for each supervised process
This means applications can just write files in their current working directory.

Plus, error messages from applications that don’t start up without a
configuration file will now show a useable path (like
/perm/home/prometheus/prometheus.yml) instead of a path in the root directory
(like /prometheus.yml).
2023-02-11 17:50:47 +01:00
Mark Drayton 3142fec4b0 support passing command line flags to /divert (#166) 2023-02-06 19:09:53 +01:00
Michael Stapelberg d2987c2469 remove CLONE_NEWNS by default (applications should do it themselves)
CLONE_NEWNS breaks running containers via podman with messages such as:

ERRO[0000] error joining network namespace for container 607b4936f51907dcf534a9d7c87ffce578611257bca9d9e05abba712e4f67ad9: error retrieving network namespace at /run/netns/cni-1aa4aa68-74d2-dacf-6b86-7bbe11a0af36: unknown FS magic on "/run/netns/cni-1aa4aa68-74d2-dacf-6b86-7bbe11a0af36": 1021994

Before this change, podman worked interactively via breakglass, but not from a
gokrazy-supervised service.

related to https://github.com/gokrazy/gokrazy/issues/44
2022-04-08 23:57:39 +02:00
oliverpool 0acbbadb6e supervisor: stop service on exit 0
fixes #125
2022-04-05 21:56:53 +02:00
Michael Stapelberg 0bcf6191bd status: allow running once or in a loop
fixes https://github.com/gokrazy/gokrazy/issues/117
2022-03-21 23:45:40 +01:00
Michael Stapelberg 0506e68f72 Revert "reset attempt counter when restarting a service manually"
This reverts commit 2935c1de91.

Breaks breakglass
2022-03-13 10:34:36 +01:00
Michael Stapelberg 2935c1de91 reset attempt counter when restarting a service manually
fixes https://github.com/gokrazy/gokrazy/issues/117
2022-03-12 19:21:24 +01:00
Michael Stapelberg 931e085d7f supervise: fix nil pointer dereference when process was not created 2022-02-26 11:18:45 +01:00
Darshil Chanpura ca0fa41749 supervise: added optional configuration to wait for clock (#105)
gokrazy.go: added a NewWaitForClockService() which enables waitForClock configuration
supervise.go: added waitForClock boolean in service{} and changed the behaviour from environment variable to flag

Signed-off-by: Darshil Chanpura <darshil@thatwebsite.xyz>
2022-01-13 09:19:25 +01:00
Anup Chenthamarakshan f20133ae5d supervise: wait for child processes (#107)
With gokrazy/gokrazy#106, we're sending a TERM signal to service
processes and their immediate children. Service processes are being
waited on by `cmd.Wait()`, which will reap any kernel state associated
with it.  However, its child processes don't necessarily get reaped
(depending on whether its parent had time to clean up before exiting).

With this change, we explicitly wait for everything in the service
process group to exit and prevent zombies.
2022-01-13 09:09:12 +01:00
Anup Chenthamarakshan 87f82b194d supervise: wait for services to stop before reboot (#106)
Currently, rebooting/upgrading the instance sends a TERM signal to all
running services, waits 1 second and then reboots. Processes that take
longer to cleanly stop can't do so.

Instead, give each service up to 15s to do a clean shutdown. Reboot 15s
after the command is sent, or after all services are stopped, whichever
comes first.

To make it easier to kill entire process tree for a service, create a
per-service process group. Stopping the service can be done by sending a
single signal to the process group.
2022-01-12 21:52:51 +01:00
Michael Stapelberg 813306b73d supervise: ignore -ESRCH when signaling process
This means the process has already exited, but should not be treated as an
error. This fixes using “gok run” for crash-looping processes, and also the stop
button in the web interface.
2022-01-09 10:42:08 +01:00
Michael Stapelberg 604d56adb4 json: only include pid if Process() is non-nil 2021-12-27 09:25:12 +01:00
Michael Stapelberg 0e70ad8c1d transparently add service when diverting an unknown service
This allows running “gok run” for prototyping, even for software you have not
included in the currently running gokrazy image.

fixes https://github.com/gokrazy/gokrazy/issues/88
2021-12-18 19:09:17 +01:00
Anup Chenthamarakshan af5773f40f status: live tail logs (#100)
Create a /log endpoint for streaming stdout/stderr logs for processes.
Replace status page stdout/stderr to call into /log to stream logs and
live update page.
2021-12-13 09:17:44 +01:00
Michael Stapelberg b07a22daa4 add /divert handler
This diverts existing services to their temporary counterparts, uploaded via the
/uploadtemp handler.

related to https://github.com/gokrazy/gokrazy/issues/88
2021-11-21 16:46:18 +01:00
Christian Heusel 54d80ad29d commandstring is now separated and quoted (#95)
Output before:
  2021/09/15 13:34:00 gokrazy: attempt 1, starting [/user/echo test 123]
Output now:
  2021/09/15 13:34:00 gokrazy: attempt 1, starting ['/user/echo' 'test' '123']
2021-09-29 22:54:50 +02:00
Michael Stapelberg 31c057fb8e supervise: start programs in their $HOME directory 2021-08-07 11:08:50 +02:00
andig 0e2a0ad88a Provide json status api (#82) 2021-01-17 19:20:54 +01:00
Michael Stapelberg 5809d7289e respect passed-in cmd.Env
related to issue #65
2021-01-17 18:42:26 +01:00
Michael Stapelberg 11dacf4264 remote syslog: one Write() call per \n-terminated line
We don’t want newlines in individual remote syslog lines.
2020-07-19 17:26:11 +02:00
Michael Stapelberg b93a58e5c8 status: print module info details
fixes https://github.com/gokrazy/gokrazy/issues/59
2020-05-30 18:17:38 +02:00
Michael Stapelberg 32f88999da set HOME=/perm/$basename when starting services
Previously, HOME was inherited from the environment of the init process, which
has HOME=/ set. Of course, / is not writable on gokrazy, so this change makes
things less strict and should therefore not break any deployments.
2020-05-27 18:50:52 +02:00
Michael Stapelberg 6beb2e16aa implement remote syslog as a platform feature
To configure, run the following command in an interactive shell (e.g. via
breakglass, or when mounting the permanent partition of the SD card on the
host):

  mkdir /perm/remote_syslog
  echo 10.0.0.76:514 > /perm/remote_syslog/target

I recommend using a (static) IP address for increased reliability, so that
remote syslog works even when DNS does not.

fixes #50
2019-12-10 22:15:42 +01:00
Michael Stapelberg c74265523b implement XSRF/CSRF protection for /stop and /restart
While stopping/restarting processes seems like a nuisance at best, it’s good
style to prevent these attacks.

This commit the Double-Submit Cookie protection, which seems appropriate for our
architecture and demands. See also:
https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#Double_Submit_Cookie
2018-06-25 18:38:08 +02:00
Michael Stapelberg 7dc7a36757 supervise: refactor to use one HTTP handler 2018-06-25 18:27:23 +02:00
Michael Stapelberg 91da7026f8 reboot: send SIGTERM to processes, wait for 1s
This way, programs can flush state to permanent storage if they need to.
2018-06-17 08:53:19 +02:00
Michael Stapelberg 38af7fd18d Initial commit 2017-03-04 11:22:48 +01:00