Skip to content

Fix shelltime service not running on Linux#168

Merged
AnnatarHe merged 1 commit intomainfrom
claude/fix-shelltime-service-3UYQq
Dec 26, 2025
Merged

Fix shelltime service not running on Linux#168
AnnatarHe merged 1 commit intomainfrom
claude/fix-shelltime-service-3UYQq

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

The Linux systemd service was failing to start due to two issues:

  1. BaseFolder was missing from template data in GetDaemonServiceFile, causing {{.BaseFolder}} to render as empty, resulting in invalid daemon path "/bin/shelltime-daemon" instead of the correct path.

  2. $USER environment variable is not available in systemd user services, causing getent passwd $USER to fail. Replaced with $(id -un) which reliably returns the current username without depending on environment.

This aligns the Linux implementation with the working macOS version.

The Linux systemd service was failing to start due to two issues:

1. BaseFolder was missing from template data in GetDaemonServiceFile,
   causing {{.BaseFolder}} to render as empty, resulting in invalid
   daemon path "/bin/shelltime-daemon" instead of the correct path.

2. $USER environment variable is not available in systemd user services,
   causing getent passwd $USER to fail. Replaced with $(id -un) which
   reliably returns the current username without depending on environment.

This aligns the Linux implementation with the working macOS version.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves two critical issues that prevented the shelltime service from starting on Linux systems. The changes ensure that the systemd service correctly identifies the daemon's executable path and reliably determines the current user, thereby aligning the Linux implementation with the functional macOS version and improving service stability.

Highlights

  • Systemd Service Path Fix: The BaseFolder variable was missing from the template data used to generate the systemd service file, causing the daemon path to be incorrectly rendered as /bin/shelltime-daemon. This has been corrected by including l.baseFolder in the template execution.
  • Reliable Username Retrieval: The $USER environment variable is not consistently available in systemd user services, leading to failures in getent passwd $USER. This has been replaced with $(id -un) to reliably retrieve the current username, ensuring the service starts correctly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@AnnatarHe AnnatarHe merged commit 9008e56 into main Dec 26, 2025
2 checks passed
@AnnatarHe AnnatarHe deleted the claude/fix-shelltime-service-3UYQq branch December 26, 2025 03:46
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 26, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
model/daemon-installer.linux.go 0.00% 2 Missing ⚠️
Flag Coverage Δ
unittests 20.02% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
model/daemon-installer.linux.go 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses two issues that were preventing the shelltime systemd service from starting on Linux. The fixes, which involve adding a missing BaseFolder to the template data and using a more reliable method to get the username, are appropriate and directly solve the problems described.

I've included a couple of suggestions for further improvement. The main suggestion is to refactor the ExecStart command in the systemd service file to use systemd's native specifiers (%s and %h). This would make the service definition cleaner, more robust, and independent of shell command parsing, while also simplifying the Go code that generates the service file.

err = tmpl.Execute(&buf, map[string]string{
"UserName": username,
"UserName": username,
"BaseFolder": l.baseFolder,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This line correctly adds the BaseFolder to the template data, fixing one of the bugs.

However, as mentioned in my comment on model/sys-desc/shelltime.service, the service file can be improved to use systemd's %h specifier for the home directory. If you apply that suggestion, {{.BaseFolder}} will no longer be needed in the template, and this line can be removed.

[Service]
Type=simple
ExecStart=/bin/sh -c 'exec $(getent passwd $USER | cut -d: -f7) -l -c "{{.BaseFolder}}/bin/shelltime-daemon"'
ExecStart=/bin/sh -c 'exec $(getent passwd $(id -un) | cut -d: -f7) -l -c "{{.BaseFolder}}/bin/shelltime-daemon"'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this change correctly fixes the issue with $USER not being available, the ExecStart command can be significantly simplified and made more robust by using systemd's built-in specifiers.

You can replace the complex shell invocation with a more direct command that uses %s for the user's shell and %h for the user's home directory. This avoids shelling out to id, getent, and cut, making the service file cleaner and less dependent on external commands. Adopting this would also make the change in daemon-installer.linux.go unnecessary.

ExecStart=%s -l -c "%h/.shelltime/bin/shelltime-daemon"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants