I'm trying to run some services on a ubuntu server using process() (from Symfony\Component\Process\Process)
$process = new Process(['systemctl', '--user', 'start', $serviceName]);
try {
$process->mustRun();
}
catch (ProcessFailedException $ex) {
Log::alert($ex->getMessage());
}
but I'm getting the following error:
The command "'systemctl' '--user' 'start' 'some_service_name.service'" failed.
Exit Code: 1(General error)
Working directory: /
Output:
Error Output:
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>#.host --user to connect to bus of other user)
Any help would be much appreciated!
I figured it out, for anyone facing the same problem the argument "--machine=username#.host" was missing.
so the end result should be something like this:
$process = new Process(['systemctl', '--machine=USER_HERE#.host', '--user', 'start', $serviceName]);
try {
$process->mustRun();
}
catch (ProcessFailedException $ex) {
Log::alert($ex->getMessage());
}
(replace the USER_HERE with your user)
Related
when i try to run serve in laravel i got this error
Symfony\Component\Process\Exception\RuntimeException
The provided cwd "C:\laravel projects\eccomer/../public_html" does
not exist.
at C:\laravel
projects\eccomer\vendor\symfony\process\Process.php:344
340▕ }
341▕ }
342▕
343▕ if (!is_dir($this->cwd)) { ➜ 344▕ throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.',
$this->cwd));
345▕ }
346▕
347▕ $this->process = #proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs,
$this->options);
348▕
1 C:\laravel
projects\eccomer\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:128
Symfony\Component\Process\Process::start(Object(Closure))
2 C:\laravel
projects\eccomer\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:68
Illuminate\Foundation\Console\ServeCommand::startProcess()
i try anything but does not work
i fixed error like this :
in app/Providers/AppServiceProvider.php file in boot funcation i copy this code:
public function boot()
{
Paginator::useBootstrap();
}
and my problem fixed
I need to create a file and copy it somewhere by some code from cypress .
the first step is done by using cy.writeFile and now myfile.txt is created
Now i need to copy it somewhere like c:/lib/Sth
i used this command cy.exec('cp myfile.txt c:/lib/sth')
it shows this error message :
CypressError: cy.exec('cp myfile.txt c:/lib/sth') failed because the command exited with a non-zero code. Pass {failOnNonZeroExit: false}` to ignore exit code failures.
Information about the failure:
Code: 127
I add {failOnNonZeroExit: false} to my code to ignore error , it works , but my file is not copied.
is there any other solution to copy my file from cypress ??
A work-around you could do is set up a custom cypress task to execute a command.
Something like
// cypress/plugins/index.ts
const { exec } = require('child_process');
/**
* #type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
async execute(command: string) {
return new Promise((resolve, reject) => {
try {
resolve(exec(command));
} catch (e) {
reject(e);
}
});
},
});
};
Then execute like so
cy.task('execute', 'cp myfile.txt c:/lib/sth');
This was a potential solution I came up with when cy.exec() didn't work for me either when trying to execute a relatively complex node script.
Another thing you could try is to create a really simple script that copies the file, and try executing that script.
Best of luck!
Usecase: I want to send jenkins job console log to elasticsearch, from there to kibana so that i can visualise the data.
I am using logstash plugin to achieve this. For freestyle job logstash plugin configuration is working fine but for jenkins pipeline jobs I am getting all required data like build number, job name, build duration and all but it is not showing the build result i.e., success or failure it is not showing.
I tried in two ways:
1.
stage('send to ES') {
logstashSend failBuild: true, maxLines: -1
}
2.
timestamps {
logstash {
node() {
sh'''
echo 'Hello, World!'
'''
try {
stage('GitSCM')
{
git url: 'github repo.git'
}
stage('Initialize')
{
jdk = tool name: 'jdk'
env.JAVA_HOME = "${jdk}"
echo "jdk installation path is: ${jdk}"
sh "${jdk}/bin/java -version"
sh '$JAVA_HOME/bin/java -version'
def mvnHome = tool 'mvn'
}
stage('Build Stage')
{
def mvnHome = tool 'mvn'
sh "${mvnHome}/bin/mvn -B verify"
}
currentBuild.result = 'SUCCESS'
} catch (Exception err) {
currentBuild.result = 'FAILURE'
}
}
}
}
But in both ways I am not getting build result i.e., success or failure in my elasticsearch or kibana.
Can someone help.
I didn't find a clear way to do that, my solution was add those lines at the end of the Jenkinsfile:
echo "Current result: ${currentBuild.currentResult}"
logstashSend failBuild: true, maxLines: 3
In my case, I dont need it to send all console logs, only one log with the result per job.
I'm running my services in ballerina composer, then I'm using Windows cmd to invoke the service using the curl but cmd is complaining that curl is not a recognized command.
How could I do it in cmd?
Please help.
Create your service file, here it is hello_service.bal.
import ballerina/http;
endpoint http:Listener listener {
port:9090
};
service<http:Service> hello bind listener {
sayHello (endpoint caller, http:Request request) {
http:Response response = new;
response.setTextPayload("Hello World!\n");
_ = caller -> respond(response);
}
}
2. Run it on cmd. ballerina run hello_service.bal
3. Make a new main.bal file.
import ballerina/http;
import ballerina/log;
import ballerina/io;
endpoint http:Client clientEndpoint {
url: "http://localhost:9090"
};
function main(string... args) {
// Send a GET request to the Hello World service endpoint.
var response = clientEndpoint->get("/hello/sayHello");
match response {
http:Response resp => {
io:println(resp.getTextPayload());
}
error err => {
log:printError(err.message, err = err);
}
}
}
4. ballerina run main.bal.
5. You can see the result as Hello World! on cmd now.
You don't need to use cURL to invoke Ballerina HTTP services. You can use the HTTP client you normally use (e.g., Postman). If you really want to, you can install cURL in Windows as well: https://curl.haxx.se/download.html.
I've got a Jenkins job with a try..catch structure:
try
{
[do work here]
}
catch(err)
{
}
Is there any way, from inside the catch block, that I can tell whether the build failed or was aborted by the user?
I've tried looking at err.getMessage(), err.getCause(), err.toString(), and currentBuild.result, but none of them consistently tell me whether it failed or was aborted.
AFAIK there's no consistent way to tell if a build was failed or aborted. When a user interrupts a build a java.lang.InterruptedException is thrown, so you could start with that. Be careful with other code which could throw an InterruptedException, like the input() step when aborted.
So you could do something like:
try
{
[do work here]
}
catch(err)
{
if (err instanceof InterruptedException) {
[handle error]
} else {
[handle error]
}
}
The aborted status will be setted at build.status or currentBuild.result,
according to the issue from Jenkins official Jira issue (
https://issues.jenkins-ci.org/browse/JENKINS-43339 ):
Regrettably, not much we can do here - the ABORTED status, in some cases, doesn't get set until the Pipeline finishes executing, so we can't tell from Declarative that we should be treating the build as ABORTED.