Q: Why did you build it manually when GitHub builds automatically?
GitHub builds take a long time depending on the number of posts, and debugging is very difficult as changes are not reflected in real-time.
Check Jekyll installation, RubyGems.org
Command summary
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev
rvm install 2.7.3
sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
type rbenv
rbenv install -l ########### Select proper version for you
rbenv install 3.2.4
rbenv global 3.2.4
ruby -v
echo "gem: --no-document" > ~/.gemrc
gem install bundler
gem update --system 3.5.11
gem env home
gem install rails -v 7.0.4
gem search '^rails$' --all
rbenv rehash
rails -v ########### You can change rails version, but recommend to try default version
gem update
gem install jekyll bundler ########### Install jekyll bundler
jekyll -v ########### Check jekyll version
Ruby is a dynamic, open-source programming language known for its simplicity and productivity. It features an elegant syntax that is easy to read and write, making it a popular choice for web development, scripting, and more. Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.
Gems are packaged libraries or applications written in Ruby. They allow developers to share and reuse code efficiently. Gems can be easily installed and managed using the gem
command-line tool. A typical gem includes:
Jekyll is a simple, blog-aware, static site generator. It transforms plain text into static websites and blogs. Jekyll processes content written in Markdown or Liquid templates and generates a complete, static site that can be served by any web server. Key features of Jekyll include:
gem install jekyll
jekyll new my-awesome-site
cd my-awesome-site
bundle exec jekyll serve
http://localhost:4000
to see your site.This code has been modified to address initial build errors in ubuntu 22.04
, but it may vary depending on your environment. Please carefully review the logs and make necessary adjustments. (2024-06-18
)
# Install build tools for your system
sudo apt-get update
sudo apt-get install build-essential libssl-dev libreadline-dev zlib1g-dev
# Attempt to install sass-embedded manually
gem install sassc
gem install sass-embedded -v '1.62.0'
# Update Bundler to the latest version
gem install bundler
# Install missing gems specified in the Gemfile
bundle install
# Clean the Bundler environment to remove unused gems
bundle clean --force
# Reinstall the gems specified in the Gemfile
bundle install
# Build the Jekyll site
jekyll build
# Serve port default: 4000
jekyll serve
# Specific port serving
jekyll serve --port 4001
If the build fails, check the logs for any template errors or review the _config.yml
file, then try building again.
To clean build, del _sites
and jekyll serve
_site
directory._site
directory. This ensures that the build results are accurate and ready for serving. Overlapping CSS files can cause errors, so be mindful of their priorities.serve
command builds and serves the site, but it can be affected by existing content in the _site
directory or the browser cache. Pay close attention to the HTML, CSS, and build order to avoid issues.
rm Gemfile.lock
bundle install
jekyll build
jekyll serve
"plugins": ["livereload"]
, you can use jekyll serve --reload
instead of jekyll serve
.include
and assets
.head.html
and post.html
or body
in jekyll template.config.yml
in jekyll template.You can visit GitBlog, built with this guide. Happy Coding!
TL;DR
# Step 1: Create a New Script
nano /home/daniel/start_label_app.sh
# Add the following content to the script:
#!/bin/bash
source /home/daniel/Public/venv/flask/bin/activate
pip install -r /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/requirements.txt
python /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/label_app.py
# Save and exit the text editor, then make the script executable:
chmod +x /home/daniel/start_label_app.sh
# Step 2: Modify the Service File
sudo nano /etc/systemd/system/label_app.service
# Replace the content with the following:
[Service]
User=daniel
Group=www-data
WorkingDirectory=/home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main
ExecStart=/bin/bash /home/daniel/start_label_app.sh
Restart=always
StandardOutput=file:/var/log/label_app_output.log
StandardError=file:/var/log/label_app_error.log
# Save the service file and exit the text editor.
# Step 3: Apply the Service File and Restart the Service
sudo systemctl daemon-reload
sudo systemctl restart label_app.service
# Step 4: Check the Logs and Service Status
sudo systemctl status label_app.service
cat /var/log/label_app_error.log
# Troubleshooting
# If issues persist, check error logs and ensure paths are correct. Adjust the script as needed.
systemctl
is a command-line utility that allows you to manage systemd services on Linux-based operating systems. This tool is commonly used to start, stop, restart, enable, and disable services. In this guide, we’ll walk through the process of setting up a systemd service to manage a Flask application that runs within a Python virtual environment.
First, we need to create a script that will activate the virtual environment and start the Flask application. This script will also ensure that the necessary Python dependencies are installed.
nano /home/daniel/start_label_app.sh
Add the following content to the script:
#!/bin/bash
source /home/daniel/Public/venv/flask/bin/activate
python /home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main/label_app.py
This script does three main things
venv
).requirements.txt
file.Save the script and exit the text editor.
chmod +x /home/daniel/start_label_app.sh
Next, we need to modify the systemd service file to execute our new script.
sudo nano /etc/systemd/system/label_app.service
Replace the content with the following:
[Service]
User=daniel
Group=www-data
WorkingDirectory=/home/daniel/Desktop/git_ram/gorani-dev/private/label-app/label-flask-main
ExecStart=/bin/bash /home/daniel/start_label_app.sh
Restart=always
StandardOutput=file:/var/log/label_app_output.log
StandardError=file:/var/log/label_app_error.log
Explanation:
User
and Group
: Specifies the user and group under which the service will run.WorkingDirectory
: The directory where the Flask application is located.ExecStart
: Specifies the command that systemd will run when starting the service. Here, we point it to our script.Restart=always
: Ensures the service will automatically restart if it fails.StandardOutput
and StandardError
: Log files where the service’s output and errors will be recorded.After modifying the service file, you need to reload the systemd manager configuration to apply the changes, and then restart the service.
sudo systemctl daemon-reload
sudo systemctl restart label_app.service
Finally, check to make sure the service is running correctly and review the logs for any potential issues.
sudo systemctl status label_app.service
This command will provide details about whether the service is running or if there were any issues during startup.
cat /var/log/label_app_error.log
This command will show you the error log, where any issues related to the Flask application startup will be recorded.
If you still encounter issues, the error logs should give you specific clues about what went wrong. Common issues might include incorrect paths, missing dependencies, or syntax errors in the script.
By following these steps, you can set up a robust systemd service to manage your Flask application, ensuring it runs smoothly and restarts automatically if needed.