navigator-services
Utilities > Services, a departure from DN (DOS had no service manager) -- navigator/lib/system/services/ (the Backend interface in common.py with Unit, run/failure, Journal/LogFile/EditPlan, Follower;
SKILL.md.claude/skills/navigator-services/SKILL.md
GitHubServices
Not DOS Navigator's. DOS had no service manager, so the whole window is a departure, asked for. It is recorded in
the docstring of navigator/lib/system/services/__init__.py, the #: comment above Utilities > Services in
main_menu.nml, and the window's markup. It is Process list's sibling and is built the same way
(navigator-processes).
The interface (navigator/lib/system/services/)
- One
Backendper service manager (common.py):name,title, a closedverbstuple, capability flags (user_scope,all_types,reload_after_edit,restart_after_edit,states_need_root,refresh_floor) and the methodsrefusal,valid_name,installed,gather,act,details,log(aJournal(argv, readable)orLogFile(path, pattern)),edit_plan(anEditPlan(path, seed, line, warning)),after_editandstates. Each module (systemd.py,openrc.py) keeps its work in module functions and a thin class over them, so tests patch the module function (systemd.unit_file,openrc.INIT_D) and the class picks it up. - Every command goes through
common.run(argv)(LANG=C,EINFO_COLOR=NO, a timeout, no stdin) -- one patch point for every backend.common.failure()reads a refusal (polkit's Access denied, OpenRC's superuser access required, Permission denied...) asOSError(EPERM), whichelevate.refused()takes for As root; anything else isEIOwith what was said. - Shared in
common.py:UNKNOWN(?, a state the user may not read) andwith_states()filling it,SYSTEM_LOGS(socklog'severything/current,/var/log/messages,/var/log/syslog) andsystem_log()-- the F3 fallback OpenRC, runit and SysVinit share, filtered to the service's name -- andpid1().run()takes atimeout(SysVinit'sstatusgets 3 s).LogFile.guessedmakes the title say a log was found by name. Unithasbackend(the name of the one that read it) andstartup(systemd's file state, or OpenRC's runlevels joined,disabledfor none).running/failedcover both managers' words.__init__.py:BACKENDS,current()([services] managernames one, else the first whoserefusal()is empty: systemd, then OpenRC, then runit, then SysVinit -- last because Gentoo and Devuan run OpenRC under a sysvinitinit),refusal_reason()for the menu's grey, and the dispatchers the window calls --gather(oncurrent(), droppinguser/all_typesit cannot do), andact/details/log/edit_plan/after_editonbackend_of(unit). The window calls only these, so a window test patchesservices.gather,services.act.- Adding a manager: a module with a
Backendsubclass andBACKEND, an entry inBACKENDS, its name inServicesData.MANAGERS(settings.py writes the tuple out: it is read before the backends can be imported), and its verbs' refusal words incommon.REFUSALSif new.
systemd (systemd.py)
gather(user, all_types)mergeslist-units --all(load, active, sub, description) withlist-unit-files(the file's state). A unit installed but never loaded is only in the second and is showninactive/dead. An instance takes its template's state; a template (getty@.service) is left out.--output=jsonfirst, the plain columns when it is refused (systemd < 246).VERBS(8, mask/unmask included) andvalid_unit()(systemd's characters, never a leading-, a dot required).act()runssystemctl [--user] --no-ask-password VERB -- NAME:--no-ask-passwordkeeps polkit off the terminal Navigator draws on.details()issystemctl status --lines=0 --full(exit 3 for a stopped unit is no failure).- F3:
Journal(journal_argv(...), can_read_journal(unit))-- a user unit, root, or a member ofsystemd-journal/adm/wheelreads it all. - F4 (
edit_plan): a masked unit is refused byunit_file()(systemd may still report the package's file as itsFragmentPath).edit_target()opens the fragment itself when it is the administrator's own (underadmin_dir(), compared afterrealpath, so a link in/etcto a package's file is still the package's), else the drop-in<admin_dir>/<unit>.d/override.conf, seeded byoverride_text()with the package's file commented out.after_editisdaemon-reload.
OpenRC (openrc.py)
gather()runs two commands, never one per service:rc-status --servicelist(name and the first word in the brackets -- newer OpenRC prints an uptime after it) andrc-update show --verbose(name | runlevels, empty for none). The description is the script'sdescription=line, read from the first 64 KiB of/etc/init.d/<name>.VERBS: start/stop/restart/reload throughrc-service NAME VERB; enable isrc-update add NAME default; disable readsrc-update showagain and deletes it from every runlevel (boot too) -- again, because the root helper gets only the name. No mask, no user services, no other kinds: the window greys them.valid_service(): a script's file name, never a leading-, never a/.installed()(a script by that name in/etc/init.d) is what the root helper checks beyond it.- F3 (
log): the service's ownoutput_log=/error_log=(a plain path, no variable, in/etc/conf.d/<name>first, then the script) when the file is there; else the first ofSYSTEM_LOGSwithpattern= its name -- the viewer shows only the lines holding it, approximate, and the title says so; elseENOENT. - F4 (
edit_plan):/etc/conf.d/<name>, seeded when new byconf_text()with the script'sNAME=lines commented out (notdepend()or functions). Noafter_edit:restart_after_edit, so a save makes the window offer a restart of a running service.
runit (runit.py)
- No database, only directories: definitions in the first of
DEFINITION_DIRS(/etc/sv, Artix's/etc/runit/sv), enabled = a link to one inservice_dir()($SVDIR, else the first ofSERVICE_DIRS). A directory placed in the supervised directory itself is listed too. It is the manager only as the first process (pid1() == "runit"): Debian's runit can supervise under systemd. gather(): every definition and enabled entry; onesv status <svdir>/...over the enabled. A disabled one isdownwith nothing read;startupisenabled,enabled, down(adownfile) ordisabled. No descriptions in runit: the column is what therunscript's lastexecruns.supervise/is root's on Void, sosv statuswarns access denied per service:parse_statusreports that as refused, andgathermarks the enabledUNKNOWN(states_need_root). A warning that is not a refusal (norunsvyet) isfail.states()is the same fixedsv status, raisingEPERMwhen every one was refused -- what the helper'sservice_statesruns.- Verbs:
sv -w 7 start|stop|restart|reload <svdir>/X(a disabled one is refused: enable it first); enable links the definition in; disable removes the link only if it is a link into the definitions -- a directory placed there is never removed.installed()is a definition by that name. - F3:
svlogd_dir()-- the last/pathaftersvlogdinlog/run-- givesDIR/current, trusted as written (a root-only log directory cannot be looked into; the viewer offers As root). Elsecommon.system_log(Void'svloggergoes to syslog). - F4:
confwhenreads_conf(run)(Void's[ -r conf ] && . ./conf), seeded withruncommented out; else therunscript itself withEditPlan.warning(an update of its package may replace it), which the window asks OK/Cancel on before opening.restart_after_edit.
SysVinit (sysvinit.py)
- No list and no states: services are the executable files in the first of
INIT_DIRS; the description is the LSB header'sShort-Description(header()joins continued lines) or Red Hat's# description:; start-up is the runlevels whoserc<N>.d(under the first ofRC_BASES) has anS<NN><name>link,bootforrcS.d. It is the manager whenpid1() == "init"and/etc/inittabexists. - Safety rules, each tested:
- Never listed:
HIDDEN(rc,halt,reboot,sendsigs,umountfs...),dpkg/rpmleftovers, and anyshutdown_only()script (LSB starts it only in 0/6 and stops it in 0 or 6). F5 onhaltmust be impossible. statusruns only wherehas_status()finds astatuscase: an old script that ignores its argument would start. Others areunknown(no status action), nothing run.statusrunsPARALLEL(8) at once, eachSTATUS_TIMEOUT(3 s); a hang isunknown(no answer). Codes: 0running, 1/2fail, 3stopped, 4 or a refusalUNKNOWN(read as root like runit's), elseunknown.installed()-- what the root helper requires -- is a listed script owned byOWNER(root) and writable by nobody else: a script the user could change would be their code run as root.
- Never listed:
- Verbs: the script itself (
/etc/init.d/X VERB, neverservice, which may hand over to systemd); exit 4 (LSB's insufficient privilege) isEPERM.verbsis a property: enable/disable only withenabler()'supdate-rc.d(defaultsfirst when it has no links at all, thenenable/disable) orchkconfig(--add, thenon/off). refresh_floor = 15: each read is a process per script. The window'sTimerchild (ticker,interval: root.refresh_ms()) is[services] refreshraised to the backend's floor, 0 turning it off; it follows the setting at once and stops with the window.- F3:
/var/log/<name>.log(guessed), elsecommon.system_log. F4:settings_file()-- the/etc/defaultor/etc/sysconfigdirectory the script names -- seeded with OpenRC'sconf_textwhen new; else the script with a warning.
As root
roothelper._Helper's ops (OPS is built from public methods):
service(manager, verb, unit): the manager must be inBACKENDS, the verb in itsverbs, the namevalid_nameandinstalled; thenbackend.act()-- the command line is always the backend's. A user unit is never offered root: its manager is the user's own.after_edit(manager): the backend'safter_editwhenreload_after_edit, else nothing.service_states(manager): for a backend withstates_need_rootonly, its ownstates()-- no name or command from the client.journal_follow(unit, path, lines)(systemd only) writesjournalctl --followinto an existing file of the asking user's, opened through_pinnedwithout following a link and never created;journal_stop(pid)stops only a pid it started, andserve()stops them all in afinally.
The window (navigator/widgets/shell/service_window/, service_list/)
ServiceWindow.backendisservices.current()from__init__. A manager other than systemd is named in the title (Services (OpenRC)) and the first column says Service. What the backend has not is greyed inrefusal()(Not something OpenRC does): a verb outside itsverbs, User units, All types (whose boxes are alsodisabled, and their key does nothing).ServiceListis aColumnList(inprocess_list.py, shared withProcessList). Rows are.running,.inactive(dim),.failed(bold and underlined: a colour of its own failedtest_no_theme_draws_an_unreadable_pair) and.masked(italic).- Reads go through
Background("nav-services")with a read counter, running_read_units. There is no read inmounted(): the_follow_vieweffect's first run reads, because_read_foris None. The cursor is kept by name. - States only root may read (
UNKNOWN): an explicit read (reload(): opening, Ctrl+R, after an action) with root access already open also calls the helper'sservice_statesand keeps the result in_root_states. The timer's read (reload(explicit=False)) never calls the helper, so an open window never keeps root access alive pastroot_timeout; it fills unknowns from_root_statesand the status line says states read as root at HH:MM. With none, it says states need root: Ctrl+R reads them as root; Ctrl+R then asks As root first (_rescan) when root access is not open. - Keys: F3 log, F4 edit (not Filter, as Process list's F4 is), Enter details, F5 start, F6 restart, F7 reload, F8/Del stop (asks), Ctrl+E enable, Ctrl+D disable, Ctrl+U user units, Ctrl+A all types, Ctrl+N/Ctrl+L sort, Ctrl+S/Alt+F filter, Ctrl+R re-read. Mask (asks) and Unmask are in the menu only.
- Every verb command subclasses
ServiceVerb, but navkit delivers a command toon_<its own class name>, so the window aliases each handler name toon_service_verb. - A refused action, for a system service with elevation available, goes through
ask_as_rootandELEVATION.call("service", manager=unit.backend, ...)withrelease()in afinally.
F4 in the window
_edit()takes theEditPlan. A seeded (new) file first gets its directory (_override_dir: as the user, or the helper'smakedirsafter As root) because the editor's save does not create directories; it then opens as a new document with the seed inserted and the cursor onplan.line. Comments only, so saving it unchanged changes nothing.- A directory made by this F4 is removed when the editor closes with the file never written (and nothing else
there):
EditWindow.after_closecalls_discard_unusedon a thread -- as the user, else through the helper'srmdironly while root access is still open. It never asks for root again just to tidy up. - The window learns of a save through
Shell.on_file_saved, which callsunit_file_saved(path)on every window that has it. A path from_editingthen runsservices.after_edit(systemd: daemon-reload; refused, straight to the helper'safter_editwhen root access is already open, else after As root) or, for a backend withrestart_after_edit, asks to restart the service if it runs.
F3 in the window (journal_window.py)
open_log()asksservices.logon a thread. AJournalgoes toopen_journal(): an empty 0600 file intempdir.private_dir(), the follower (as the user, orjournal_followas root withELEVATION.hold()), up toFIRST_LINESfor the first bytes, then aJournalWindow(aFileWindow) with Follow end on. Itsunmounting()stops the follower and deletes the file on a thread (stopping); anatexithook stops any left. It keeps no File View History record.- A
LogFilegoes toopen_log_file(): a plainFileWindowon the file (view_as_rootafter As root when the user may not read it),show_lines(LinePattern(pattern))when there is a pattern, then Follow end. The title says Log: <name>, and (its lines in <path>) when filtered.
Tests
tests/test_services.py(systemd): the merge, sorting, names,act's refusal, the helper's ops (no process for a bad manager, verb or name), and the window withservices.gatherpatched,[services] refresh0 and[services] managerpinned to systemd (service_run, so the host's own manager does not matter) -- filter, cursor, boxes, F5/F8/Ctrl+E, As root withELEVATION.callfaked (pass every other op through: a root drive another test left mounted callschildren), F3's journal, F4's file and drop-in, and the unsaved drop-in's directory removed.tests/test_services_openrc.py:rc-status/rc-updateparsing and merge, what each verb runs, refusals, details, F3's own/filtered/no log, F4's seed,current()'s choice, the helper'sinstalledcheck, and the window withmanager = "openrc"andopenrc.refusalpatched to "" (else the shell greys Services on a machine without OpenRC): greying, As root, F3 filtered, F4 then the restart offer./etc/init.d,/etc/conf.dand the system logs are theetcfixture's, intmp_path.tests/test_services_sysvinit.py: theetcfixture (LSB, Red Hat, no-status, hanging, code-4, shutdown-only and hidden scripts,rc2.d/rcS.dlinks,/etc/defaultand/etc/sysconfig),common.runfaked with itstimeoutkeyword: what is listed and never run, status codes, each verb with and without a tool, the helper's ownership check (OWNERpatched to the test's user to pass), F3, F4, and the window's 15 s floor (spying onApplication.call_every,service_run(..., refresh=3)).tests/test_services_runit.py: thetreefixture (definitions, a supervised directory with links, adownfile,svlogdandvloggerloggers, aconf-readingrun, a directory placed in the supervised directory),sv statusfaked throughcommon.run(states, and every one refused), each verb (never removing a directory), F3, F4 and its warning, the helper'sservice_states/service, and the window:?with its hint, Ctrl+R reading as root withELEVATION.runningfaked (a class property: patchtype(ELEVATION)), the timer's read keeping the stale states, Ctrl+R asking when root access is closed.