Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary pack script opt #4010

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/CPackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ macro(package to_one name home_page scripts_dir)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${home_page})
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${scripts_dir}/postinst)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${scripts_dir}/postinst;${scripts_dir}/prerm)

set(CPACK_RPM_SPEC_MORE_DEFINE "%define debug_package %{nil}
%define __os_install_post %{nil}")
set(CPACK_RPM_COMPONENT_INSTALL YES)
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(CPACK_RPM_PACKAGE_URL ${home_page})
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${scripts_dir}/rpm_preuninst)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${scripts_dir}/rpm_postinst)
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/local)
set(CPACK_RPM_PACKAGE_RELOCATABLE ON)
Expand Down
10 changes: 10 additions & 0 deletions package/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

install_dir=/usr/local/nebula
daemons=(storaged metad graphd)
for daemon in ${daemons[@]}
do
if [[ ! -f $install_dir/scripts/nebula.service ]] ; then
$install_dir/scripts/nebula.service stop ${daemon}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This operation can be dangerous in a production environment. I suggest that we do not do this implicitly.

fi
done
9 changes: 9 additions & 0 deletions package/rpm_preuninst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

daemons=(storaged metad graphd)
for daemon in ${daemons[@]}
do
if [[ ! -f $RPM_INSTALL_PREFIX/scripts/nebula.service ]] ; then
$RPM_INSTALL_PREFIX/scripts/nebula.service stop ${daemon}
fi
done
2 changes: 2 additions & 0 deletions scripts/nebula.service
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ function start_daemon {
local command="${executable} --flagfile ${config}"
INFO "Starting ${daemon_name}..."
eval ${command}
local port=$(get_port_from_config ${config})
wait_for_port_listening ${port} 20 || WARN "Timed out waiting for ${daemon_name} to finish starting, but it may still be running"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to implement this logic in nebula process.
and the behavior should be same with running in container.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just like readinessprobe in k8s, curl a http interface?

INFO "Done"
}

Expand Down
13 changes: 13 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ function wait_for_exit {
done
}

# To wait for a port to be listened on
# args: <port number> <seconds to wait>
function wait_for_port_listening {
local port=${1}
local seconds=${2}
is_port_listened_on ${port} || return 0
while [[ ${seconds} > 0 ]]; do
sleep 0.1
is_port_listened_on ${port} || return 0
seconds=$(echo "${seconds} - 0.1" | bc -l)
done
}

# To read a config item's value from the config file
# args: <config file> <config item name>
function get_item_from_config {
Expand Down