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

build: Provide setup script for running as a systemd service #35

Merged
merged 4 commits into from
Feb 15, 2022

Conversation

travipross
Copy link
Collaborator

@travipross travipross commented Dec 14, 2021

I've created a script which I think will walk the user through the process of installing as a service. I've tested a few times in several variations on my machine and it seems to work great, so I think it's good to include.

../resources/poglink.service \
${OUTPUT_PATH}

# TODO: Copy sample config to ~/.poglink if it doesn't exist yet
Copy link
Collaborator Author

@travipross travipross Dec 14, 2021

Choose a reason for hiding this comment

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

Will circle back to this before merging; Otherwise it would need to be abundantly obvious to the user that they need to create/populate this file.

Comment on lines 7 to 27
# Check whether virtual environment is active
if [ -z "${VIRTUAL_ENV}" ] && [ "${FORCE}" != "true" ]; then
echo "Warning: Virtual environment not detected! It is highly recommended to install this program to run under a virtual environment. Please activate your virtual environment and run this script again."
echo "If you're certain you'd like to continue without a virtual environment, you can run again with 'FORCE=true'."
exit 1
fi

# Install poglink python package
pip install poglink

# Obtain path to python executable
if [ -z "${VIRTUAL_ENV}" ]; then
PYTHON_EXECUTABLE="$(which python3)"
else
PYTHON_EXECUTABLE="${VIRTUAL_ENV}/bin/python3"
fi
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what I came up with to help encourage usage within a virtual environment, while not explicitly preventing someone from ignoring that advice.

I use pyenv and it should work equally well with venv. Please do test if you'd like though.

@travipross travipross force-pushed the travis-service branch 2 times, most recently from a59603b to eb33506 Compare December 15, 2021 02:24
docs/systemd-installation.md Show resolved Hide resolved
docs/systemd-installation.md Show resolved Hide resolved
resources/poglink.service Show resolved Hide resolved
cd "$(dirname "$0")"

# Check whether virtual environment is active
if [ -z "${VIRTUAL_ENV}" ] && [ "${FORCE}" != "true" ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If FORCE=true then this block will pass and it will install poglink on the system Python environment. This might be desireable if using a dedicated VM for this bot and didn't want to bother with a venv when you knew there was nothing to worry about conflicting with.

fi

# Install poglink python package
pip install poglink
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't want to pin a specific version or force an update; I feel like that should be up to the user to decide if they want a specific version or want to update.

Comment on lines +36 to +41
sudo install \
-v \
--backup \
--suffix .bak \
../resources/poglink.service \
${SERVICE_FILE_PATH}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like to use install instead of cp here because it allows me to set a backup option, in case you run accidentally and overwrite a service file you've modified.

Comment on lines +44 to +46
sudo sed -i "s@\#\#PYTHON\#\#@${PYTHON_EXECUTABLE}@g" "${SERVICE_FILE_PATH}"
sudo sed -i "s@\#\#DATA_DIR\#\#@${DATA_DIR}@g" "${SERVICE_FILE_PATH}"
sudo sed -i "s@\#\#USER\#\#@${USER}@g" "${SERVICE_FILE_PATH}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a simple search and replace for the delimited tokens I've defined.

Comment on lines +49 to +55
if [ ! -e ${DATA_DIR}/config.yaml ]; then
echo "Poglink config not found in $DATA_DIR; Using creating from sample..."
mkdir -p ${DATA_DIR}
cp ../sample-config.yaml ${DATA_DIR}/config.yaml

echo -e "\n\nIMPORTANT!!! A sample configuration file has been created at ${DATA_DIR}/config.yaml . Please edit this file before starting the application for the first time."
fi
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will leave existing config files alone if they are already found in the data directory.

@travipross
Copy link
Collaborator Author

Housekeeping reminder @FM-17

@codecov
Copy link

codecov bot commented Jan 19, 2022

Codecov Report

Merging #35 (23c4984) into main (1e610d0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #35   +/-   ##
=======================================
  Coverage   73.13%   73.13%           
=======================================
  Files          13       13           
  Lines         510      510           
=======================================
  Hits          373      373           
  Misses        137      137           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e610d0...23c4984. Read the comment docs.

@travipross travipross mentioned this pull request Jan 19, 2022
Copy link
Owner

@FM-17 FM-17 left a comment

Choose a reason for hiding this comment

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

Finally got around to reviewing this. It looks great. I'd say we're good to merge pending this follow-up, and any other changes that may be needed to bring this up to date.

@FM-17
Copy link
Owner

FM-17 commented Feb 15, 2022

Housekeeping reminder @FM-17

Housekeeping reminder @travipross

@travipross
Copy link
Collaborator Author

Housekeeping reminder @FM-17

Housekeeping reminder @travipross

Elaboarating on the housekeeping reminder: Want to circle back to this before merging.

@travipross
Copy link
Collaborator Author

Elaboarating on the housekeeping reminder: Want to circle back to this before merging.

Actually, nevermind. I had mostly already addressed that concern and I feel the concept will be subject to further review anyway when looking at #41. Merging now.

@travipross travipross merged commit 592844d into main Feb 15, 2022
@travipross travipross deleted the travis-service branch February 15, 2022 17:20
@github-actions
Copy link

github-actions bot commented Oct 1, 2022

🎉 This PR is included in version 0.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup instructions should include running native python code as a service.
2 participants