I'm not sure if what I am trying to do is possible, and I'm fairly new to perl so I'd appreciate any help.
My perl application will use system() to issue commands to Perforce that will create a devel/workspace, integrate, sync, etc. But obviously I can't integrate until my devel is created, and I can't sync unless some condition is met, so on and so forth. Also when my code is synced and I run it, I'm not sure how to tell if it finished or not either.
So I'm wondering how to say (slack pseudo code):
system(create my devel);
wait until devel created
system(integrate blah);
wait until integration complete
system (launch test);
wait until test complete;
etc...
I looked at other questions and saw the possibility of using forks, but I am not familiar with how to code that in this context.
Thanks
Normally, the system command in Perl will wait until the command you asked it to run has completed. This would work exactly the same as if you entered the command at a shell prompt, the program would run and the shell prompt would appear only when the command has completed whatever it is doing.
Perforce has a free Perl module downloadable from http://www.perforce.com/downloads/Perforce/20-User?qt-perforce_downloads_step_3=6#qt-perforce_downloads_step_3#52, with documentation at http://www.perforce.com/perforce/r12.1/manuals/p4script/02_perl.html#1047731.
But it sounds like you need more experience with Perl multiprogramming and IPC. Have you read the Camel book?
Related
I've followed this tutorial:
https://www.linode.com/docs/guides/start-service-at-boot/
and set everything up.
Since my problem is exactly this:
https://unix.stackexchange.com/questions/298027/restart-systemd-service-when-output-is-no-longer-generated
I've also followed the answers here.
The problem with the solution: after 7 hours of runtime, the program stuck. No output generated, systemd didn't restart it.
in my_service.service are both suggested mandatory entries
everything else is correct
WatchdogSec=30
Restart=on-watchdog
Can I manually make my Rust program communicate with systemd? And if yes - how? I'd love to make it notify systemd at particular lines periodically.
The docs couldn't be more minimal:
https://docs.rs/systemd/latest/systemd/daemon/constant.STATE_WATCHDOG.html
I don't understand a single thing..
Another example crate libsystemd, there's 3 search results for WatchDog and this one is the most relevant I guess.
https://docs.rs/libsystemd/latest/libsystemd/daemon/enum.NotifyState.html#variant.Watchdog
IDK how I am able to accomplish anything here. Do I just paste this line anywhere in the program that I want?
libsystemd::daemon::NotifyState
how will it know the PID?
In any case: each of those packages has multiple methods, and my program hangs after anywhere from 1-24 hours, trial and error might take weeks.
How can I make my Rust program communicate to the systemd from inside threads, or if impossible - just manually set it up and ensure the WatchDog receives the signal as I want it? What's the line of code for sending a single notification from Rust program to systemd?
As mentioned above the go-to logic is simple: if no print output, restart the program.
You have to send the message somehow. By looking for functions that use the NotifyState I found both systemd::daemon::notify and libsystemd::daemon::notify either of which will do.
For example:
use systemd::daemon::{notify, STATE_WATCHDOG};
notify(false, [(STATE_WATCHDOG, "1")].iter()).unrwap();
I want to daemonize a lua script;
Fortunately, I see that the luaposix package offers a unistd interface, so I can call fork() etc. Unfortunately, it DOES NOT offer the setsid() function, so though I've been able to write a simple daemon, it's not complete.
I also saw that there's a luarocks package named luadaemon available spefically for this. Unfortunately, it fails to compile correctly and seems to not really be supported or developed.
I'm thinking of writing my own 'luadaemon' in C if I can't find an alternative, but I wanted to double-check first.
Is there any way to daemonize a lua script?
PS:
I'm not interested in systemd etc options
I already know about start-stop-daemon
What I'm interested in is if there's any way to write a daemon in lua directly only using lua modules.
We have a startup script for an application (Owned and developed by different team but deployments are managed by us), which will prompt Y/N to confirm starting post deployment. But the number of times it will prompt will vary, depends on changes in the release.
So the number of times it will prompt would vary from 1 to N (Might be even 100 or more than that).
We have automated the deployment and startup using Jenkins shell script jobs. But startup prompts number is hardcoded to 20 which might be more at sometime.
Could anyone please advise how number of prompts can be handled dynamically. We need to pass Y whenever there is pattern in the output "Do you really want to start".
Checked few options like expect, read. But not able to come up with a solution.
Thanks in advance!
In general, the best way to handle this is by (a) using a standard process management system, such as your distro's preferred init system; or, if that's not possible, (b) to adjust the script to run noninteractively (e.g., with a --yes or --noninteractive option).
Barring that, assuming your script reads from standard input and not the TTY, you can use the standard program yes and pipe it into the command you're running, like so:
$ yes | ./deploy
yes prints y (or its argument) over and over until it's killed, usually by SIGPIPE.
If your process is reading from /dev/tty instead of standard input, and you really can't convince the other team to come to their senses and add an appropriate option, you'll need to use expect for this.
I am executing a few external programs from a Perl script and want to automatically handle prompts from that program. I know what the prompts are, they are not error conditions, and I want the script to handle them and not the user.
What's best practice for this?
Thanks
My first stop would be the Expect module. I'm not sure if I'd need a second stop after that.
Here is the problem:
i must move some files from one host to another, ok i use scp for
it.
But i need use it without blocking console, so should use scp &. But my job will killed after disconnecting (a heard it`s something called hup signal) so i found some tricks for fixing this.
But i wanna see progress bar after some time and all that tricks couldnt work because when i use jobs - it display jobs that only for these session.
So how to fix my problem ?
P.S. Sorry for my English.
I am not sure it is what you want but I'll suggest GNU Screen. It allows you to run a program so that when you log out, the program continues execution in the background. Later you can log back in and resume interaction with the program.
I guess you want ability to detach -and- attach terminal - The tool is called screen.