Shell run parallel job and simulate the enter key

wolffnx

Aspiring Daemon

Reaction score: 226
Messages: 667

sounds strange, but I want do this:

run the scripts at boot in parallel mode, that is easy
I add a "&" at the final of
Code:
run_rc_command "$1"

but the problem is, that it's dont add the break caracter and the next init script text output just run beside the text of the script that run before
and create a mess

I believe that I am not the first who think to do this

any idea guys?
 

ralphbsz

Son of Beastie

Reaction score: 2,186
Messages: 3,136

I'm not sure I understand.

You want to run the rc scripts (the ones stored in /etc/rc.d) in parallel? That's certainly possible. The best-known and most widely deployed implementation (note: I said best-known and widely used, not most popular, not best liked!) is systemd, which is available in many Linux distributions. There is OpenRC, which I think is used by default on GhostBSD. For a while, a user here on the forum was making a big drama about wanting to use "nosh", and I've completely forgotten what the final outcome of that was.

Anyway, if you want to run the rc scripts in parallel, you have to solve the problem of how to preserve their ordering. Most rc scripts have very strict ordering requirements: They require certain other scripts to run before them, and they provide services to scripts that come after them. This is documented in the comments at the top of each rc script, but I'm not 100% sure that the documentation is complete and sufficient. Whatever you implement has to preserve that ordering, so if a script requires X, you need to wait with starting that script until whatever script provides X has actually finished. Total ordering of a graph is a well-known problem in computer science (I think students do it as homework in their first year), and implementing it using "wait" statements is not all that difficult.

I think your problem you mention above is that the output of the scripts is intermingled. Welcome to running parallel programs! Ultimately, the mixing of output depends on what device is used for the output (/var/log/messages via syslog, or the console, or the kernel-internal dmesg mechanism). Typically, if output is printed line-by-line, lines will be intermingled, but not broken apart. So if three services are running, all saying "hallo", "progress" and "goodbye", you might get this output:
Code:
A: Hallo
B: Hallo
B: Progress at 01:12 doing X
C: Hallo
A: Progress at 01:23 doing Y
A: Goodbye
C: Progress at 01:45 doing Z
B: Goodbye
C: Goodbye
To accomplish this, you need to audit every single rc script and every program used within the rc scripts, and make sure they always print a while line at a time, in this style: "echo A: Progress at `date` doing X", or the equivalent with a printf statement in C or the equivalent in other languages. If scripts/programs break this apart in this way:
Code:
echo -n A: Progress at ""
echo -n `date` ""
echo Doing X
Then it is possible that things get mixed up:
Code:
B: Progress at C: Progress at A: Goodbye 01:12 doing Y 01:23 doing Z

The underlying problem is the line buffering of devices and open files. If you want to do this right, you re-implement syslog to allow logging multi-line packets. For people who implement parallel systems, this is a standard problem, and typically one has a young software engineer spend a few weeks writing a logging package that does the right thing.
 
OP
wolffnx

wolffnx

Aspiring Daemon

Reaction score: 226
Messages: 667

I come very closer, the only thing is adapt the init scripts
the magic comes with ydotool

I made a test script and its works well, but, requires 1 condition :

the script needs a
Code:
start_cmd
function to execute ydotool after execute the service/daemon
(bellow the line of the principal command)

for example

Code:
start_cmd="function_start"

function_start()
{
#the real command is ls in this case
/bin/ls
#then ydotool 'press' enter
/usr/local/bin/ydotool key enter
}

run_rc_command "$1" &

and that's it , but I have some trouble with some scripts,like dbus
what have only the
Code:
command="/usr/local/bin/dbus-daemon"
directive
and when create the
Code:
start_cmd
function the dbus daemon return an error of "no arguments"
look at the web for some info on rc scripts, but I had to keep searching
yes, the inits scripts needs to be modified(minimal) but is not hard as is looks
 

Alain De Vos

Daemon

Reaction score: 546
Messages: 1,890

ydotool has no man page ...
the following gives the rc order,
Code:
rcorder /etc/rc.d/* /usr/local/etc/rc.d/*
I want to write a script to put the network interface on and off.
With something like
Code:
ifconfig lo0 up
ifconfig lo0 inet 127.0.0.1/8 alias
ifconfig re0 inet6 -ifdisabled
ifconfig re0 inet6 accept_rtadv
ifconfig re0 up
ifconfig re0 inet6 accept_rtadv up
ifconfig -n re0 inet alias 0.0.0.0 netmask 255.0.0.0 broadcast 255.255.255.255 up
Or the use bhyve,
Code:
ifconfig -g viid-4c918@
ifconfig bridge create name vm-public group vm-switch up
ifconfig vm-public group viid-4c918@
ifconfig vm-public link random
ifconfig vm-public addm re0
ifconfig -n bridge0
 
Top