Init Scripts: Do I Need a PID File?
I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance.
We run an application that utilizes JBOSS and I need to be able to handle it like a daemon using an init script. This is my first time writing an init script and I understand that often '.pid' files are used to keep track of a process using an init script, however I wonder if they are really needed in my situation.
For example, when I go to use the "stop" function of my init script, I can have it check the .pid file to get the process ID, or I can simply have it get the PID using "checkproc".
Here is an example of what I have written.
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
function _stop {
# Check if JBOSS is running..
if [ -z "$JBOSSPID" ]; then
echo "Service is not running.."
exit
fi
# Attempt to shutdown JBOSS gracefully..
echo "Stopping service.."
./stop_jboss.sh
# Loop until JBOSS PID no longer exists..
RUNNING=0
while [ "$RUNNING" == "0" ]
do
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
if [ "$JBOSSPID" == "" ]; then
RUNNING=1
fi
done
}
I've wrote my "start" and "status" functions to obtain the PID like this as well. I tested it and it seems to work fine, but I don't know if there is something I'm missing that could go wrong without a .pid file. Are there any reasons for me to scrap this logic and instead utilize a .pid file?
bash shell-script init-script
bumped to the homepage by Community♦ 14 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance.
We run an application that utilizes JBOSS and I need to be able to handle it like a daemon using an init script. This is my first time writing an init script and I understand that often '.pid' files are used to keep track of a process using an init script, however I wonder if they are really needed in my situation.
For example, when I go to use the "stop" function of my init script, I can have it check the .pid file to get the process ID, or I can simply have it get the PID using "checkproc".
Here is an example of what I have written.
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
function _stop {
# Check if JBOSS is running..
if [ -z "$JBOSSPID" ]; then
echo "Service is not running.."
exit
fi
# Attempt to shutdown JBOSS gracefully..
echo "Stopping service.."
./stop_jboss.sh
# Loop until JBOSS PID no longer exists..
RUNNING=0
while [ "$RUNNING" == "0" ]
do
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
if [ "$JBOSSPID" == "" ]; then
RUNNING=1
fi
done
}
I've wrote my "start" and "status" functions to obtain the PID like this as well. I tested it and it seems to work fine, but I don't know if there is something I'm missing that could go wrong without a .pid file. Are there any reasons for me to scrap this logic and instead utilize a .pid file?
bash shell-script init-script
bumped to the homepage by Community♦ 14 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49
add a comment |
I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance.
We run an application that utilizes JBOSS and I need to be able to handle it like a daemon using an init script. This is my first time writing an init script and I understand that often '.pid' files are used to keep track of a process using an init script, however I wonder if they are really needed in my situation.
For example, when I go to use the "stop" function of my init script, I can have it check the .pid file to get the process ID, or I can simply have it get the PID using "checkproc".
Here is an example of what I have written.
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
function _stop {
# Check if JBOSS is running..
if [ -z "$JBOSSPID" ]; then
echo "Service is not running.."
exit
fi
# Attempt to shutdown JBOSS gracefully..
echo "Stopping service.."
./stop_jboss.sh
# Loop until JBOSS PID no longer exists..
RUNNING=0
while [ "$RUNNING" == "0" ]
do
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
if [ "$JBOSSPID" == "" ]; then
RUNNING=1
fi
done
}
I've wrote my "start" and "status" functions to obtain the PID like this as well. I tested it and it seems to work fine, but I don't know if there is something I'm missing that could go wrong without a .pid file. Are there any reasons for me to scrap this logic and instead utilize a .pid file?
bash shell-script init-script
I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance.
We run an application that utilizes JBOSS and I need to be able to handle it like a daemon using an init script. This is my first time writing an init script and I understand that often '.pid' files are used to keep track of a process using an init script, however I wonder if they are really needed in my situation.
For example, when I go to use the "stop" function of my init script, I can have it check the .pid file to get the process ID, or I can simply have it get the PID using "checkproc".
Here is an example of what I have written.
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
function _stop {
# Check if JBOSS is running..
if [ -z "$JBOSSPID" ]; then
echo "Service is not running.."
exit
fi
# Attempt to shutdown JBOSS gracefully..
echo "Stopping service.."
./stop_jboss.sh
# Loop until JBOSS PID no longer exists..
RUNNING=0
while [ "$RUNNING" == "0" ]
do
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
if [ "$JBOSSPID" == "" ]; then
RUNNING=1
fi
done
}
I've wrote my "start" and "status" functions to obtain the PID like this as well. I tested it and it seems to work fine, but I don't know if there is something I'm missing that could go wrong without a .pid file. Are there any reasons for me to scrap this logic and instead utilize a .pid file?
bash shell-script init-script
bash shell-script init-script
edited Nov 9 '15 at 14:21
Raphael Ahrens
7,01152846
7,01152846
asked Nov 9 '15 at 14:11
azurepancakeazurepancake
4615
4615
bumped to the homepage by Community♦ 14 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 14 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49
add a comment |
1
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49
1
1
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49
add a comment |
1 Answer
1
active
oldest
votes
You can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"
The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.
So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f241857%2finit-scripts-do-i-need-a-pid-file%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 can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"
The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.
So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.
add a comment |
You can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"
The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.
So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.
add a comment |
You can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"
The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.
So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.
You can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"
The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.
So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.
answered Nov 9 '15 at 14:31
cristicristi
448414
448414
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f241857%2finit-scripts-do-i-need-a-pid-file%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
1
You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
– jordanm
Nov 9 '15 at 14:28
actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
– cas
Nov 10 '15 at 1:49