'How can I make my Rust program run at startup?

I know about how to run programs at startup on Windows, but not Linux (even though I use Linux myself). Is there a library I can use which will automatically run my program at startup? I have tried Googling about it and couldn't find anything, the closest thing I found were Windows binding for Rust.

I want to minimize the amount of code I have to actually write because when I do write a lot of code, it ends up looking kind of messy, and I don't want the other people working on the project to suffer. That being said, all I am asking for is if there is a library for what I want to do or if there is a way to run my program at startup with minimal amounts of code.



Solution 1:[1]

There is no simple solution because it depends on your user's Linux distribution, its version, your user's desktop environment and its version (or if the user logs in with a text console or through the network). Plus, what should happen if the user logs in multiple times? Should the program run once for each session? Or once overall for each user?

Things you can look at:

And more generally: https://wiki.archlinux.org/title/Autostarting

Solution 2:[2]

Try pm2

It supports:

  1. start at boot time of server.
  2. logging,
  3. remote monitoring.
  4. works everywhere.

As other ppl mentioned start at boot time is nothing what your application should care about.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jmb
Solution 2 Boris Ivanov