You are not logged in.
Pages: 1
I took a look at shed (version shed.v0.2.0-120-gd7af2d4) to see how you manage is processes are running. I guess I made something completely wrong due to my impatience or missing experience with gaming X sessions. Nevertheless, I got what I already suspected. shed was reporting that is was already running (line 142) when that was really not the case. It's because shed relies on pidfiles only. (If there is one single thing I should name that was giving me most issues with SysV init then it is the reliance on pidfiles in the "early"? init scripts.)
Instead you could use start-stop-daemon, and if that's not installed busybox start-stop-daemon (busybox is widely used in Linux installations because of its use in initrd) but (1) I have no idea about non-Linux UNIX systems and (2) I don't think that it would help in checking for the shed script.
Here is a suggestion for some "stuff"
that might work too.
#!/bin/sh
#
is_running() {
/usr/bin/awk '#
function getarg(name, p) {
if (argi >= ARGC) {
printf ("%s: missing arg: %s\n", program, name) >>"/dev/stderr";
exit (1);
}
p = ARGV[argi];
ARGV[argi++] = "";
return (p);
}
BEGIN {
program = "is-running";
argi = 1;
pidfile = getarg("pidfile");
pid = getarg("pid");
if (pidfile != "" && pidfile != ".") {
getline pid2 <pidfile;
close(pidfile);
if (pid == "" || pid == ".")
pid = pid2;
else if (pid != pid2)
exit (1);
}
fn = "/proc/" pid "/cmdline";
FS = "\0";
getline <fn;
close (fn);
for (i = 1; ARGV[argi] != ""; argi++) {
if (ARGV[argi] == "" || ARGV[argi] != $(i++))
exit (1);
}
exit (0);
}' "$@"
return $?
}
is_running "$@"
exit $?is_running is a draft of a shell function *relying on /proc* (again: don't know about non-Linux) accepting 3 or more parameters:
the name of the process' pidfile; this is optional
the process' pid; optional: if pidfile is given its value is compared against pid and they are expected to match; if missing the pidfile's content is used as pid
the process' executable (optional - if not set only pids would compared but that would not make much sense for this function)
addtional optional parameter would be compared against the process' command line parameters.
Arguments for process executable or parameter might be empty string to ignore the for comparison.
So, how could that been used in shed? Just guessing here, but testing for a running service should be
is_running $pidfile "" $EXECbut that does not work for interpreted scripts (bad). Adding `$E_ARGS` should help
is_running $pidfile "" $EXEC $E_ARGSbut the script's `$EXEC` must be the interpreter (i.e. no use of `#!` here).
Also
is_running $startfile "" /bin/sh shedshould check if shed is running. You can replace `/bin/sh` with `""` if you are unsure about the shell interpreter.
Yor are right, EDX-0, pico-init has become large (it's no longer "pico"). I see two major scenarios where it fits:
as pidN service controller/supervisor if the use case is strong enough (e.g. for a Rasperry Pi gadget device) or
as experimental or test kit for processes control: as soon as you know what you want and need you would copy&paste idea and/or code to your project.
Just yesterday I got an idea for a possible scenario 2
.
@EDX-0, I really like what you are doing here and I think we should have more of that (to have alternatives to choose from or copy&paste code or ideas). One of my projects is to work on a Raspberry Pi gadget where I combine system services into a "functional device". I don't give a pfff about writing systemd units for them but instead I use my own process supervisor for that. This too makes starting the relevant services pid1-agnostic. That is easier to handle (you do not have to understand the 300+ unit options) and it is easier to port to other pid1's (SysV, systemd, s6, runit/nitro, you-name-it).
Having said that, I must admit that I'm not going to use your controller because I have my own pony on the lawn: https://codeberg.org/awk-scripting/pico-init. It supervises the process but requires bash or busybox ash (or any other shell with `wait -n` which excludes dash) for that. I'm just going to add runlevels
to it which brings the script to approx. 1500 lines of code
(comments and empty line count extra).
Of course, "no one" needs another editor and this is also not what the apps do. E.g., the console notes app is a large GNU awk script that uses vi (or nano or your-editor) for editing. So, what is the script doing?
- Years ago I decided to put my notes where they belong - into the project directories. To keep the directories uncluttered, all notes go into the file Notes.md and they begin with a `###` markdown header. So the app's first function is to know the format and present the notes as directory.
- Displaying notes inserts ANSI sequences to color markdown markup and uses `less -XRF` for output.
- Then the app understands where to look when I enter `Lin:` (opens Linux.md from the "wiki" directory) or "micro:" (opens Notes.md from micro-boot directory).
- The app knows where to find all files when I run a search through all of my notes (`//systemd +boot`)
- Then the app can open links in a console (or GUI) browser, start a shell, open the editor or duplicate itself in a new xterm, tmux or screen window.
- It also knows how to open files on a gvfs directory.
So while it's true, that there are plenty of good text editors, there is so much more around organising and finding notes and this is what the apps really do.
Thank you for posting this. Your app gave me the final push to create an X-version for a note format I'm using for years now in Linux terminals. It's written in Java and I understand it's not for everyone but in case you are looking for additional inspiration, the documentation is here: https://codeberg.org/awk-scripting/Note … ntation.md
Hello EDX-0, I like your shell approach and the idea of being agnostic of window system. init-system or whatever is there. (I'm using a similar thing for my own stuff on Raspberry Pi.) I have a small suggestion just in case there are distro maintainers with aversion of too much shell commands:
get_shed_cgroup_2() {
awk '
BEGIN {
pid = ARGV[1];
cmd = "ps ax -o pid,cgroup,cmd=CMD ";
while (cmd | getline > 0) {
if ($0 ~ /grep/ || $0 !~ /shed/)
continue;
else if ($1 != pid)
continue;
sub(/^.*::\//, "", $2);
print $2;
}
}' "$shed_pid"
}
shed_pid=$$
get_shed_cgroup
get_shed_cgroup_2Pages: 1