Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
nucleo
Commits
84cef848
Commit
84cef848
authored
4 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Let geth create a clean synced copy at startup, before starting up for full service
parent
ae252b1a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/singlestart.sh
+84
-39
84 additions, 39 deletions
bin/singlestart.sh
with
84 additions
and
39 deletions
bin/singlestart.sh
+
84
−
39
View file @
84cef848
...
...
@@ -10,39 +10,42 @@ bootnodekeyfile=${BFANETWORKDIR}/bootnode/key
# Bail out if anything fails.
trap
"exit 1"
ERR
# Detect children dying
trap
"reaper"
SIGINT SIGCHLD
unset
LOGDIR LOGPIPE PIDIDX
declare
-A
PIDIDX
trap
"killallprocs"
SIGTERM
trap
"reaper"
SIGCHLD
trap
"killprocs"
SIGTERM
trap
"killallprocs"
EXIT
unset
LOGPIPE PIDIDX ALLPIDIDX TMPDIR SHUTTING_DOWN
declare
-A
PIDIDX ALLPIDIDX
SHUTTING_DOWN
=
0
function
reaper
()
{
local
wecare
=
0
local
reaped_a_child_status
=
0
# Find out which child died
for
pid
in
${
!PIDIDX[*]
}
do
kill
-0
$pid
2>/dev/null
&&
continue
reaped_a_child_status
=
1
local
rc
=
0
wait
$pid
||
rc
=
$?
||
true
echo
"***
${
PIDIDX
[
$pid
]
}
(pid
$pid
) has exited with value
$rc
"
local
name
=
${
PIDIDX
[
$pid
]
}
echo
"***
$name
(pid
$pid
) has exited with value
$rc
"
if
[
$name
=
'geth'
]
;
then
geth_rc_status
=
$rc
;
fi
unset
PIDIDX[
$pid
]
wecare
=
1
done
test
$wecare
=
1
||
return
# kill all - an extra kill doesn't hurt. I hope.
# Return if we didn't find out which child died.
if
[
$reaped_a_child_status
=
0
]
;
then return
;
fi
# Kill all other registered processes
for
pid
in
${
!PIDIDX[*]
}
do
# don't kill log.sh, because it may still be logging for us
if
[
"
${
PIDIDX
[
$pid
]
}
"
!=
"log.sh"
]
then
echo
"*** Killing
${
PIDIDX
[
$pid
]
}
(pid
$pid
)."
kill
$pid
||
true
fi
kill
-0
$pid
2>/dev/null
||
continue
echo
"*** Killing
${
PIDIDX
[
$pid
]
}
(pid
$pid
)."
kill
$pid
||
true
done
max
=
30
}
function
kill
all
procs
()
function
killprocs
()
{
SHUTTING_DOWN
=
1
if
[
${#
PIDIDX
[*]
}
-gt
0
]
then
echo
"*** Killing all remaining processes:
${
PIDIDX
[*]
}
(
${
!PIDIDX[*]
}
)."
...
...
@@ -50,6 +53,30 @@ function killallprocs()
fi
}
function
killallprocs
()
{
# merge the 2 pid list, to make killing and echoing easier
for
pid
in
${
!ALLPIDIDX[*]
}
do
PIDIDX[
$pid
]=
${
ALLPIDIDX
[
$pid
]
}
unset
ALLPIDIDX[
$pid
]
done
killprocs
if
[
-n
"
$TMPDIR
"
-a
-e
"
$TMPDIR
"
]
then
rm
-rf
"
$TMPDIR
"
fi
}
function
startgeth
()
{
echo
"***"
Starting geth
$*
# "NoPruning=true" means "--gcmode archive"
geth
--config
${
BFATOML
}
$*
&
gethpid
=
$!
PIDIDX[
${
gethpid
}
]=
"geth"
}
# You can start as:
# BFAHOME=/home/bfa/bfa singlestart.sh
# singlestart.sh /home/bfa/bfa
...
...
@@ -75,8 +102,19 @@ else
fi
source
${
BFAHOME
}
/bin/libbfa.sh
TMPDIR
=
$(
mktemp
-d
)
mknod
${
TMPDIR
}
/sleeppipe p
sleep
987654321
>
${
TMPDIR
}
/sleeppipe &
ALLPIDIDX[
$!
]=
'sleep'
if
[
"
$VIRTUALIZATION
"
=
"DOCKER"
]
then
echo
echo
echo
echo
date
echo
$0
startup
echo
echo
"See log info with
\"
docker logs
\"
"
else
echo
"Logging mostly everything to
${
BFANODEDIR
}
/log"
...
...
@@ -86,21 +124,40 @@ else
# Docker has it's own logging facility, so we will not use our own
# logging functionality if we're in docker.
echo
"*** Setting up logging."
# Clean up logging
LOGDIR
=
$(
mktemp
-d
)
trap
"rm -rf
${
LOGDIR
}
"
EXIT
LOGPIPE
=
${
LOGDIR
}
/logpipe
LOGPIPE
=
${
TMPDIR
}
/logpipe
mknod
${
LOGPIPE
}
p
${
BFAHOME
}
/bin/log.sh
${
BFANODEDIR
}
/log <
${
LOGPIPE
}
&
PIDIDX[
$!
]=
"log.sh"
# Separate pididx for processes we don't want to send signals to
# until in the very end.
ALLPIDIDX[
$!
]=
"log.sh"
exec
>
${
LOGPIPE
}
2>&1
fi
echo
"*** Starting geth."
# "NoPruning=true" means "--gcmode archive"
geth
--config
${
BFATOML
}
&
PIDIDX[
$!
]=
"geth"
function
sleep
()
{
read
-t
${
1
:-
1
}
<
${
TMPDIR
}
/sleeppipe
||
true
}
# Start a sync
startgeth
--exitwhensynced
echo
"*** Starting monitor.js"
monitor.js &
PIDIDX[
$!
]=
"monitor.js"
# geth will exit when it has synced, then we kill it's monitor.
# Then wait here for their exit status to get reaped
while
[
"
${#
PIDIDX
[*]
}
"
-gt
0
]
;
do
sleep
1
;
done
# if it went well, start a normal geth (to run "forever")
test
$geth_rc_status
=
0
||
exit
$geth_rc_status
test
"
$SHUTTING_DOWN
"
!=
0
&&
exit
0
# regular geth
startgeth
# monitor
echo
"*** Starting monitor.js"
monitor.js &
PIDIDX[
$!
]=
"monitor.js"
# bootnode
if
[
-r
"
$bootnodekeyfile
"
]
then
...
...
@@ -109,16 +166,4 @@ then
PIDIDX[
$!
]=
"bootnode"
fi
echo
"*** Starting monitor.js"
monitor.js &
PIDIDX[
$!
]=
"monitor.js"
max
=
-1
# Exit if only 1 process remains - we hope it is log.sh, but either way,
# it is time to end.
while
[
"
${#
PIDIDX
[*]
}
"
-gt
1
-a
$max
-ne
0
]
do
sleep
1
max
=
$((
$max
-
1
))
done
killallprocs
while
[
"
${#
PIDIDX
[*]
}
"
-gt
0
]
;
do
sleep
1
;
done
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment