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

Improve .deb package creation #88

Merged
merged 24 commits into from
Aug 3, 2021
Merged

Improve .deb package creation #88

merged 24 commits into from
Aug 3, 2021

Conversation

lampkin-diet
Copy link
Contributor

  • Add systemd service creation after install .deb package
  • Add post remove action for .deb package
  • Add scripts for building .deb package and tar archive

Andrew Nikitin added 19 commits July 22, 2021 21:39
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
Signed-off-by: Andrew Nikitin <[email protected]>
.github/workflows/release.yml Show resolved Hide resolved
touch ${{ env.OUTPUT_DIR }}/${{ env.PACKAGE_NAME }}_${{ env.VERSION }}.tar.gz
tar -czf ${{ env.OUTPUT_DIR }}/${{ env.PACKAGE_NAME }}_${{ env.VERSION }}.tar.gz /home/runner/go/bin/cheqd-noded
./build_tar.sh ${{ env.PACKAGE_NAME }} ${{ env.VERSION }}
working-directory: ./build_tools

Choose a reason for hiding this comment

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

It seems strange to build that tar inside of the build_tools directory. In generally I try to make scripts to not rely on relative pathing, so that that the working directory isn't an issue. Not sure how hard that would be here with GitHub Actions, but something to think about.

Regardless, It might make more sense to have the build_tar.sh change into whatever directories it needs, and have the tar built in one level up. So it would be sitting in the same directory as build_tools/ sits.

Again... what you have it probably fine, but something to think about for the future, and have less dependency on what directory to run certain scripts from.

--name "cheqd-node" \
--description "cheqd node" \
--architecture "${ARCH}" \
--pre-install "postinst" \

Choose a reason for hiding this comment

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

Shouldn't this be --after-install? In Debian, a preinst script is executed before the archive is extracted to the filesystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now it's not very significant to run this script after install of before because we don't use cheqd-noded binary while making actions. But yes, you are right, it would be more clearly to run it --after-install

@@ -0,0 +1,79 @@
#!/bin/bash

Choose a reason for hiding this comment

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

This is a script that will be executed after EVERY install/upgrade of the .deb

So you'll need to make it idempotent

I know you want this script to be runnable as a tar installation, but here is an example postinst script I wrote for a personal project of mine that is idempotent and also managed systemd service, you could probably adapt as necessary: https://github.com/absltkaos/toddleglow/blob/master/debian/toddleglow.postinst

CHEQD_USER_NAME=cheqd

# Create cheqd user
useradd -d /home/$CHEQD_USER_NAME -m $CHEQD_USER_NAME

Choose a reason for hiding this comment

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

This will only succeed the first time the .deb is installed... after which useradd will exit non-zero and you'll have issues.

Also this should be a "system" user, so as not to conflict with people's user management (like an LDAP etc...). Also change the home directory so it is not in /home which is reserved for actual human users.

I suggest wrapping this in an if statement to look something like this:

if ! /usr/bin/getent passwd $CHEQD_USER_NAME > /dev/null 2>&1 ; then
    adduser --system ${CHEQD_USER_NAME} --home /var/lib/${CHEQD_USER_NAME}
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

EOF

# Add crontab job for daily rotation
cat <<EOF > /etc/cron.daily/cheqd-node

Choose a reason for hiding this comment

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

Why do this? Logrotate should already be running via cron.daily and the file is part of the logrotate package

$ dpkg -S /etc/cron.daily/logrotate
logrotate: /etc/cron.daily/logrotate

chmod +x /etc/cron.daily/cheqd-node

# Restart syslog
systemctl restart rsyslog

Choose a reason for hiding this comment

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

Again... what if I don't use rsyslog for log management? I don't think this should be here.

Maybe only do a restart of rsyslog IF this postinst script created /etc/rsyslog.d/cheqd-node.conf in the if statement further up and the rsyslog service is already running.

systemctl restart rsyslog

# Add systemd script
cat <<EOF > /etc/systemd/system/cheqd-noded.service

Choose a reason for hiding this comment

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

This file should be included in the tar file under /lib/systemd/system NOT /etc/systemd/system (which is reserved for admins to override values in the systemd service provided by the package etc..)

Adding it here ties the Admin's hands on being able to customize the service.

[Service]
Type=simple
User=cheqd
ExecStart=/bin/bash -c '/usr/bin/cheqd-noded start'

Choose a reason for hiding this comment

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

Why does this need to be wrapped in bash -c? Can't it just run directly?

if test -f "/etc/rsyslog.d/cheqd-node.conf"; then
rm /etc/rsyslog.d/cheqd-node.conf
# Restart rsyslog daemon
systemctl restart rsyslog

Choose a reason for hiding this comment

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

Similar comments on this hard dependency on rsyslog

Andrew Nikitin added 5 commits August 2, 2021 12:23
Copy link

@absltkaos absltkaos left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@askolesov askolesov merged commit 2fde44c into main Aug 3, 2021
@askolesov askolesov deleted the dep_additions branch August 3, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants