How I will check that the mongodb service is runing or not using terminal command?
I'm using mongodb database to save my application data into collection but by some reasons the mongodb connection is break and there is lot of problems occurs and I want to check the mongodb connection through terminal command. I searched for it and I found three commands which will be used but I'm confused that which command I have to use in the golang code.
Command 1. pgrep mongod
this command will return me PID (process Id).
Command 2. ps -ef | grep mongod
this command will returns me mongodb 15678 1 1 13:58 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf
Command 3. ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
this command I found from the stackoverflow accepted answer and it may be returns 0, 1. if there is other value except 0 then your mongodb is running as the answer say you can see link of the question
link:- https://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac
Command 4. service --status-all | grep mongod
will show me the mongod service with a signed like [ + ], or [ - ]
. In the documentation they says that if the service with [ + ]
the service is running and [ - ]
the service is stopped. But on my localhost the mongod is running and it will show me [ - ] mongod
when I execute this command. Why?
link:- https://www.rosehosting.com/blog/how-to-list-all-services-in-linux/
Please tell me that which Command I have to used to check that the mongodb is running or not I have to use that command in my golang code.
command-line bash mongodb
add a comment |
I'm using mongodb database to save my application data into collection but by some reasons the mongodb connection is break and there is lot of problems occurs and I want to check the mongodb connection through terminal command. I searched for it and I found three commands which will be used but I'm confused that which command I have to use in the golang code.
Command 1. pgrep mongod
this command will return me PID (process Id).
Command 2. ps -ef | grep mongod
this command will returns me mongodb 15678 1 1 13:58 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf
Command 3. ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
this command I found from the stackoverflow accepted answer and it may be returns 0, 1. if there is other value except 0 then your mongodb is running as the answer say you can see link of the question
link:- https://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac
Command 4. service --status-all | grep mongod
will show me the mongod service with a signed like [ + ], or [ - ]
. In the documentation they says that if the service with [ + ]
the service is running and [ - ]
the service is stopped. But on my localhost the mongod is running and it will show me [ - ] mongod
when I execute this command. Why?
link:- https://www.rosehosting.com/blog/how-to-list-all-services-in-linux/
Please tell me that which Command I have to used to check that the mongodb is running or not I have to use that command in my golang code.
command-line bash mongodb
I think if you just want to check the service is running, you can do just usesystemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is
– j-money
Jan 30 at 9:33
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
I'm not sure I understand your question, it will print info about the service tostdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?
– j-money
Jan 30 at 11:23
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf
– JJoao
Jan 30 at 11:29
add a comment |
I'm using mongodb database to save my application data into collection but by some reasons the mongodb connection is break and there is lot of problems occurs and I want to check the mongodb connection through terminal command. I searched for it and I found three commands which will be used but I'm confused that which command I have to use in the golang code.
Command 1. pgrep mongod
this command will return me PID (process Id).
Command 2. ps -ef | grep mongod
this command will returns me mongodb 15678 1 1 13:58 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf
Command 3. ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
this command I found from the stackoverflow accepted answer and it may be returns 0, 1. if there is other value except 0 then your mongodb is running as the answer say you can see link of the question
link:- https://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac
Command 4. service --status-all | grep mongod
will show me the mongod service with a signed like [ + ], or [ - ]
. In the documentation they says that if the service with [ + ]
the service is running and [ - ]
the service is stopped. But on my localhost the mongod is running and it will show me [ - ] mongod
when I execute this command. Why?
link:- https://www.rosehosting.com/blog/how-to-list-all-services-in-linux/
Please tell me that which Command I have to used to check that the mongodb is running or not I have to use that command in my golang code.
command-line bash mongodb
I'm using mongodb database to save my application data into collection but by some reasons the mongodb connection is break and there is lot of problems occurs and I want to check the mongodb connection through terminal command. I searched for it and I found three commands which will be used but I'm confused that which command I have to use in the golang code.
Command 1. pgrep mongod
this command will return me PID (process Id).
Command 2. ps -ef | grep mongod
this command will returns me mongodb 15678 1 1 13:58 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf
Command 3. ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
this command I found from the stackoverflow accepted answer and it may be returns 0, 1. if there is other value except 0 then your mongodb is running as the answer say you can see link of the question
link:- https://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac
Command 4. service --status-all | grep mongod
will show me the mongod service with a signed like [ + ], or [ - ]
. In the documentation they says that if the service with [ + ]
the service is running and [ - ]
the service is stopped. But on my localhost the mongod is running and it will show me [ - ] mongod
when I execute this command. Why?
link:- https://www.rosehosting.com/blog/how-to-list-all-services-in-linux/
Please tell me that which Command I have to used to check that the mongodb is running or not I have to use that command in my golang code.
command-line bash mongodb
command-line bash mongodb
edited Jan 30 at 10:11
gourav
asked Jan 30 at 8:59
gouravgourav
63
63
I think if you just want to check the service is running, you can do just usesystemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is
– j-money
Jan 30 at 9:33
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
I'm not sure I understand your question, it will print info about the service tostdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?
– j-money
Jan 30 at 11:23
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf
– JJoao
Jan 30 at 11:29
add a comment |
I think if you just want to check the service is running, you can do just usesystemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is
– j-money
Jan 30 at 9:33
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
I'm not sure I understand your question, it will print info about the service tostdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?
– j-money
Jan 30 at 11:23
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf
– JJoao
Jan 30 at 11:29
I think if you just want to check the service is running, you can do just use
systemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is– j-money
Jan 30 at 9:33
I think if you just want to check the service is running, you can do just use
systemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is– j-money
Jan 30 at 9:33
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
I'm not sure I understand your question, it will print info about the service to
stdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?– j-money
Jan 30 at 11:23
I'm not sure I understand your question, it will print info about the service to
stdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?– j-money
Jan 30 at 11:23
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf– JJoao
Jan 30 at 11:29
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf– JJoao
Jan 30 at 11:29
add a comment |
1 Answer
1
active
oldest
votes
You could run something along the lines of
if pgrep -x mongodd
then echo "ok"
else echo "not ok"
fi
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114054%2fhow-i-will-check-that-the-mongodb-service-is-runing-or-not-using-terminal-comman%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could run something along the lines of
if pgrep -x mongodd
then echo "ok"
else echo "not ok"
fi
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
add a comment |
You could run something along the lines of
if pgrep -x mongodd
then echo "ok"
else echo "not ok"
fi
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
add a comment |
You could run something along the lines of
if pgrep -x mongodd
then echo "ok"
else echo "not ok"
fi
You could run something along the lines of
if pgrep -x mongodd
then echo "ok"
else echo "not ok"
fi
answered Jan 30 at 11:44
JJoaoJJoao
1,40069
1,40069
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
add a comment |
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
please check this link is this commands are right to do this
– gourav
Jan 30 at 12:49
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114054%2fhow-i-will-check-that-the-mongodb-service-is-runing-or-not-using-terminal-comman%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think if you just want to check the service is running, you can do just use
systemctl status mongod.service
and then check the return code (though the name of the serivice you may have to change, i don't remember exactly what it is– j-money
Jan 30 at 9:33
@j-money Can we use this command for the code purpose will it return the status?
– gourav
Jan 30 at 10:12
I'm not sure I understand your question, it will print info about the service to
stdout
, but when a service isn't active it will give back a non-zero return value. Are you writing a bash script? Or in another language?– j-money
Jan 30 at 11:23
pgrep -ax mongod
571 /usr/bin/mongod --config /etc/mongodb.conf– JJoao
Jan 30 at 11:29