Get output of server crash from server re-spawning script
Clash Royale CLAN TAG#URR8PPP
I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you through the rather trivial process of creating such a script. However, I have slightly adapted the script and it now looks like this:
until "homebridge" -s /bin/sh pi; do
echo "Server homebridge crashed with exit code $?. Respawning.." >&2
echo "Looks like Homebridge just crashed, restarting it now..." | mail -s "Homebridge Crash" pi
rm -r /home/pi/.homebridge/accessories/cachedAccessories
sleep 1
done
It is virtually the same as the original script with the exception that it deletes a folder and waits a second before re-spawning. Furthermore, it sends some mail to my user (pi
) to let me know that the process has died and that it is re-spawning. This has been working perfectly for me with the simple omission of any sort of de-bugging. By that I mean that whilst I do get notified that the process has died, I am not presented with an output of the process when it died. It would be perfect if the mail could include, for example, the last 300 lines before the process exited in order to aid with debugging following a crash
What exactly would I need to add to the above script in order to receive a 'log' of what the homebridge
output was just before it crashed in order to debug it?
bash shell-script logs process-management
add a comment |
I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you through the rather trivial process of creating such a script. However, I have slightly adapted the script and it now looks like this:
until "homebridge" -s /bin/sh pi; do
echo "Server homebridge crashed with exit code $?. Respawning.." >&2
echo "Looks like Homebridge just crashed, restarting it now..." | mail -s "Homebridge Crash" pi
rm -r /home/pi/.homebridge/accessories/cachedAccessories
sleep 1
done
It is virtually the same as the original script with the exception that it deletes a folder and waits a second before re-spawning. Furthermore, it sends some mail to my user (pi
) to let me know that the process has died and that it is re-spawning. This has been working perfectly for me with the simple omission of any sort of de-bugging. By that I mean that whilst I do get notified that the process has died, I am not presented with an output of the process when it died. It would be perfect if the mail could include, for example, the last 300 lines before the process exited in order to aid with debugging following a crash
What exactly would I need to add to the above script in order to receive a 'log' of what the homebridge
output was just before it crashed in order to debug it?
bash shell-script logs process-management
1
Which information exactly do you need? The output onstdout
and/orstderr
? Does Homebridge write a logfile like/var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and usetail
.
– Bodo
Jan 15 at 9:39
@Bodo All output would be great, (bothstdout
andstderr
). I know that homebridge does supposedly write a log either to/var/log/homebridge.log
or/var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.
– Rocco
Jan 15 at 16:36
I suggest to find out how to enable the log output. Of course you can use something likeuntil "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something liketail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.
– Bodo
Jan 15 at 17:00
Wouldn't it be better to letsystemd
(re)start homebridge?
– Bodo
Jan 15 at 17:03
add a comment |
I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you through the rather trivial process of creating such a script. However, I have slightly adapted the script and it now looks like this:
until "homebridge" -s /bin/sh pi; do
echo "Server homebridge crashed with exit code $?. Respawning.." >&2
echo "Looks like Homebridge just crashed, restarting it now..." | mail -s "Homebridge Crash" pi
rm -r /home/pi/.homebridge/accessories/cachedAccessories
sleep 1
done
It is virtually the same as the original script with the exception that it deletes a folder and waits a second before re-spawning. Furthermore, it sends some mail to my user (pi
) to let me know that the process has died and that it is re-spawning. This has been working perfectly for me with the simple omission of any sort of de-bugging. By that I mean that whilst I do get notified that the process has died, I am not presented with an output of the process when it died. It would be perfect if the mail could include, for example, the last 300 lines before the process exited in order to aid with debugging following a crash
What exactly would I need to add to the above script in order to receive a 'log' of what the homebridge
output was just before it crashed in order to debug it?
bash shell-script logs process-management
I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you through the rather trivial process of creating such a script. However, I have slightly adapted the script and it now looks like this:
until "homebridge" -s /bin/sh pi; do
echo "Server homebridge crashed with exit code $?. Respawning.." >&2
echo "Looks like Homebridge just crashed, restarting it now..." | mail -s "Homebridge Crash" pi
rm -r /home/pi/.homebridge/accessories/cachedAccessories
sleep 1
done
It is virtually the same as the original script with the exception that it deletes a folder and waits a second before re-spawning. Furthermore, it sends some mail to my user (pi
) to let me know that the process has died and that it is re-spawning. This has been working perfectly for me with the simple omission of any sort of de-bugging. By that I mean that whilst I do get notified that the process has died, I am not presented with an output of the process when it died. It would be perfect if the mail could include, for example, the last 300 lines before the process exited in order to aid with debugging following a crash
What exactly would I need to add to the above script in order to receive a 'log' of what the homebridge
output was just before it crashed in order to debug it?
bash shell-script logs process-management
bash shell-script logs process-management
edited Jan 15 at 10:53
Rui F Ribeiro
39.8k1479132
39.8k1479132
asked Jan 15 at 9:16
RoccoRocco
11
11
1
Which information exactly do you need? The output onstdout
and/orstderr
? Does Homebridge write a logfile like/var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and usetail
.
– Bodo
Jan 15 at 9:39
@Bodo All output would be great, (bothstdout
andstderr
). I know that homebridge does supposedly write a log either to/var/log/homebridge.log
or/var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.
– Rocco
Jan 15 at 16:36
I suggest to find out how to enable the log output. Of course you can use something likeuntil "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something liketail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.
– Bodo
Jan 15 at 17:00
Wouldn't it be better to letsystemd
(re)start homebridge?
– Bodo
Jan 15 at 17:03
add a comment |
1
Which information exactly do you need? The output onstdout
and/orstderr
? Does Homebridge write a logfile like/var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and usetail
.
– Bodo
Jan 15 at 9:39
@Bodo All output would be great, (bothstdout
andstderr
). I know that homebridge does supposedly write a log either to/var/log/homebridge.log
or/var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.
– Rocco
Jan 15 at 16:36
I suggest to find out how to enable the log output. Of course you can use something likeuntil "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something liketail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.
– Bodo
Jan 15 at 17:00
Wouldn't it be better to letsystemd
(re)start homebridge?
– Bodo
Jan 15 at 17:03
1
1
Which information exactly do you need? The output on
stdout
and/or stderr
? Does Homebridge write a logfile like /var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and use tail
.– Bodo
Jan 15 at 9:39
Which information exactly do you need? The output on
stdout
and/or stderr
? Does Homebridge write a logfile like /var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and use tail
.– Bodo
Jan 15 at 9:39
@Bodo All output would be great, (both
stdout
and stderr
). I know that homebridge does supposedly write a log either to /var/log/homebridge.log
or /var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.– Rocco
Jan 15 at 16:36
@Bodo All output would be great, (both
stdout
and stderr
). I know that homebridge does supposedly write a log either to /var/log/homebridge.log
or /var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.– Rocco
Jan 15 at 16:36
I suggest to find out how to enable the log output. Of course you can use something like
until "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something like tail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.– Bodo
Jan 15 at 17:00
I suggest to find out how to enable the log output. Of course you can use something like
until "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something like tail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.– Bodo
Jan 15 at 17:00
Wouldn't it be better to let
systemd
(re)start homebridge?– Bodo
Jan 15 at 17:03
Wouldn't it be better to let
systemd
(re)start homebridge?– Bodo
Jan 15 at 17:03
add a comment |
0
active
oldest
votes
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%2f494559%2fget-output-of-server-crash-from-server-re-spawning-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f494559%2fget-output-of-server-crash-from-server-re-spawning-script%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
Which information exactly do you need? The output on
stdout
and/orstderr
? Does Homebridge write a logfile like/var/log/homebridge.log
or does it use syslog? maybe you can configure it to do this. Then it would be easy to filter the log and usetail
.– Bodo
Jan 15 at 9:39
@Bodo All output would be great, (both
stdout
andstderr
). I know that homebridge does supposedly write a log either to/var/log/homebridge.log
or/var/log/homebridge.err
as per here and I understand that tail would be a simple solution. However, neither of these files exist for me and that is why I am wondering whether it would be able to integrate it into the script shown above itself.– Rocco
Jan 15 at 16:36
I suggest to find out how to enable the log output. Of course you can use something like
until "homebridge" -s /bin/sh pi > outputfile 2>&1; do
and later use something liketail -100 outputfile
, but the file may permanently grow limited only by the available space. The regular log mechanism probably already has a mechanism for log file switching and deleting of old log files.– Bodo
Jan 15 at 17:00
Wouldn't it be better to let
systemd
(re)start homebridge?– Bodo
Jan 15 at 17:03