How to use a Rust Program as Linux Service

Elminson De Oleo Baez
3 min readMar 8, 2024

First we need to create a basic Rust program (don’t be afraid)

You need Rust (you can follow this instructions).

What we will do

A. Create a basic Rust program to save USD-EUR conversion rate to a file

B. Create a Linux Service using our Rust program

The Rust Program

Lets create a new project and fetch the USD-EUR currency pair and save it in to a file every 5 seconds (Github repo). We can insert the currency to a database or send an email (we can do anything with this data). We will be using this url https://open.er-api.com/v6/latest/USD to get the conversion rate.

❯ cargo new currency-service
Created binary (application) `currency-service` package
(base)
❯ cd currency-service

This is the Cargo.toml file content

[package]
name = "currency-service"
version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde_json = "1.0"
chrono = "0.4"

This is the main.rs file content

use std::fs::File;
use std::io::Write;
use reqwest::blocking::get;
use chrono::{Utc};
use std::thread;
use std::time::Duration;
use serde_json::json;

fn…

--

--

Elminson De Oleo Baez

Lead Software Engineer who precisely executes development projects from concept to delivery