-
Notifications
You must be signed in to change notification settings - Fork 0
Scheduled service configuration #13
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
Draft
akablockchain1
wants to merge
3
commits into
master
Choose a base branch
from
scheduled-service-configuration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ETH_WALLET_PRIVATE_KEY=PUT_YOUR_ETH_WALLET_PRIVATE_KEY_HERE | ||
| ALCHEMY_API_KEY=PUT_YOUR_ETH_WALLET_PRIVATE_KEY_HERE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Diffuse Datafeed (systemd service + timer) | ||
|
|
||
| This project allows you to schedule the `parse_and_prove_feed.sh` script using `systemd`. The script, in turn, runs the Python program `parse_prove_feed.py` with parameters from the `.env` file and writes logs to `/var/log/diffuse/parse_and_prove_feed.log`. | ||
|
|
||
| ## Installation | ||
|
|
||
| 1. Place the project files in the desired directory, for example: `~/datafeed-cli/`. | ||
| 2. Create a `.env` file based on `.env-example` and fill in the required variables. | ||
| 3. In the files `diffuse-parse-proove-feed.service` and `diffuse-parse-proove-feed.timer`, specify: | ||
| - The absolute paths to the directory containing the scripts and `.env`. | ||
| - If needed, adjust the timer frequency (by default, every 5 seconds). | ||
| 4. In `parse_and_prove_feed.sh`, specify any parameters needed for `parse_prove_feed.py`. | ||
| 5. Run the setup script: | ||
|
|
||
| ```bash | ||
| chmod +x run.sh | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| This script copies the relevant files to the system directories, reloads `systemd`, and enables the timer. | ||
|
|
||
| ## Checking Status | ||
|
|
||
| - To check the timer status: | ||
|
|
||
| ```bash | ||
| sudo systemctl status diffuse-parse-proove-feed.timer | ||
| ``` | ||
|
|
||
| - To view logs: | ||
|
|
||
| ```bash | ||
| tail -f /var/log/diffuse/parse_and_prove_feed.log | ||
| ``` | ||
|
|
||
| ## Stopping | ||
|
|
||
| To stop the service and timer: | ||
|
|
||
| ```bash | ||
| ./stop.sh | ||
| ``` | ||
|
|
||
| This script will stop and disable both the service and the timer (check with `systemctl status diffuse-parse-proove-feed.timer`). | ||
|
|
||
| ## Changing the Schedule | ||
|
|
||
| To change the run frequency, edit `OnUnitActiveSec` and other settings in `diffuse-parse-proove-feed.timer`, then run: | ||
|
|
||
| ```bash | ||
| sudo systemctl daemon-reload | ||
| sudo systemctl restart diffuse-parse-proove-feed.timer | ||
| ``` | ||
|
|
||
| All logs will continue to be written to `/var/log/diffuse/parse_and_prove_feed.log`. |
9 changes: 9 additions & 0 deletions
9
services/scheduled_parse_prove_feed/diffuse-parse-proove-feed.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [Unit] | ||
| Description=Diffuse Datafeed periodic job | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| User=PUT_YOUR_USER_HERE | ||
| WorkingDirectory=PUT_YOUR_ABSOLUT_PATH_TO_DATAFEED_CLI_HERE ; | ||
| EnvironmentFile=PUT_YOUR_ABSOLUT_PATH_TO_DATAFEED_CLI_HERE/services/scheduled_parse_prove_feed/.env ; | ||
| ExecStart=PUT_YOUR_ABSOLUT_PATH_TO_DATAFEED_CLI_HERE/services/scheduled_parse_prove_feed/parse_and_prove_feed.sh |
11 changes: 11 additions & 0 deletions
11
services/scheduled_parse_prove_feed/diffuse-parse-proove-feed.timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [Unit] | ||
| Description=Runs Diffuse Datafeed job every 5 seconds, sequentially | ||
|
|
||
| [Timer] | ||
| OnBootSec=5 | ||
| OnUnitActiveSec=5 | ||
| AccuracySec=1s | ||
| Persistent=false | ||
|
|
||
| [Install] | ||
| WantedBy=timers.target | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| mkdir -p /var/log/diffuse | ||
|
|
||
| echo "$(date) start feeding" >> /var/log/diffuse/parse_and_prove_feed.log | ||
|
|
||
| python3 cli/parse_prove_feed.py PUT_YOUR_CLI_PARAMETERS_HERE >> /var/log/diffuse/parse_and_prove_feed.log 2>&1 | ||
|
|
||
| echo "$(date) data request and proving finished: " >> /var/log/diffuse/parse_and_prove_feed.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| sudo mkdir -p /var/log/diffuse | ||
|
|
||
| sudo cp diffuse-parse-proove-feed.service /etc/systemd/system/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this design works well with exactly one task, but what if we want to have for example two in parallel with two different heartbeats? |
||
| sudo cp diffuse-parse-proove-feed.timer /etc/systemd/system/ | ||
|
|
||
| sudo chmod +x PUT_YOUR_ABSOLUT_PATH_TO_DATAFEED_CLI_HERE/services/scheduled_parse_prove_feed/parse_and_prove_feed.sh | ||
|
|
||
| sudo systemctl daemon-reload | ||
|
|
||
| sudo systemctl enable diffuse-parse-proove-feed.timer | ||
| sudo systemctl start diffuse-parse-proove-feed.timer | ||
|
|
||
| echo "System-wide service and timer have been installed and started (running under root)." | ||
| echo "Check status via: sudo systemctl status diffuse-parse-proove-feed.timer" | ||
| echo "Logs will be written to: /var/log/diffuse/parse_and_prove_feed.log" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| systemctl stop diffuse-parse-proove-feed.timer | ||
| systemctl disable diffuse-parse-proove-feed.timer | ||
|
|
||
| systemctl stop diffuse-parse-proove-feed.service | ||
| systemctl disable diffuse-parse-proove-feed.service | ||
|
|
||
| echo "Timer and service 'diffuse-parse-proove-feed' have been stopped and disabled." | ||
| echo "You can verify via: systemctl status diffuse-parse-proove-feed.timer" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much, lets change to 86400