issue145:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue145:c_c [2019/06/03 23:34] – d52fr | issue145:c_c [2019/06/07 15:43] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**One of the programs I’ve written that I use pretty much every day is something I call “media-tracker”. It’s a Ruby on Rails app that allows me to add/track movie (cinema and DVD) and game releases. Lately, I’ve also started tracking current episodes of shows from streaming services (Netflix, Crunchroll, Amazon Prime Video) due to the frequency with which I start a show, watch a chunk of it, and then notice it’s been removed from the streaming service. This way I can pick up where I’ve left off if the show pops up somewhere else or I buy a DVD of it. Long story short - I start this app in Tmux manually every time I log in. I’ve finally gotten tired of this, and instead created a small systemd service to run the script on boot.** | **One of the programs I’ve written that I use pretty much every day is something I call “media-tracker”. It’s a Ruby on Rails app that allows me to add/track movie (cinema and DVD) and game releases. Lately, I’ve also started tracking current episodes of shows from streaming services (Netflix, Crunchroll, Amazon Prime Video) due to the frequency with which I start a show, watch a chunk of it, and then notice it’s been removed from the streaming service. This way I can pick up where I’ve left off if the show pops up somewhere else or I buy a DVD of it. Long story short - I start this app in Tmux manually every time I log in. I’ve finally gotten tired of this, and instead created a small systemd service to run the script on boot.** | ||
+ | |||
+ | Un des programmes que j'ai écrits et que j' | ||
**Notes | **Notes | ||
Ligne 6: | Ligne 8: | ||
All commands have been run on an ArchLinux system. If your distribution has a different format (ie, systemctl < | All commands have been run on an ArchLinux system. If your distribution has a different format (ie, systemctl < | ||
+ | |||
+ | Notes | ||
+ | |||
+ | Cet article se concentrera sur l' | ||
+ | |||
+ | Toutes les commandes ont été lancées sur un système ArchLinux. Si votre distribution a un format différent (c' | ||
**Getting set up | **Getting set up | ||
Ligne 15: | Ligne 23: | ||
This is important, as you’ll need to tell Systemd what to set these variables to, otherwise commands will fail or simply not be found.** | This is important, as you’ll need to tell Systemd what to set these variables to, otherwise commands will fail or simply not be found.** | ||
+ | |||
+ | Faire le paramétrage | ||
+ | |||
+ | D' | ||
+ | |||
+ | echo $PATH | ||
+ | echo $GEM_HOME | ||
+ | |||
+ | C'est important, car vous devrez dire à Systemd à quelles valeurs paramétrer ces variables, sinon les commandes planteront ou ne seront simplement pas trouvées. | ||
**Decide - user or system service? | **Decide - user or system service? | ||
Ligne 24: | Ligne 41: | ||
Think about it and make your decision. Then skip ahead to the relevant section.** | Think about it and make your decision. Then skip ahead to the relevant section.** | ||
+ | |||
+ | À décider - Service utilisateur ou service système ? | ||
+ | |||
+ | Les systèmes les plus modernes ont paramétré systemd pour tourner à la fois dans une version système et dans une version spécifique à l' | ||
+ | |||
+ | 1. Les services de systemd à l' | ||
+ | 2. Les services basés sur l' | ||
+ | |||
+ | Réfléchissez-y et prenez votre décision. Puis, sautez à la section pertinente. | ||
**System-wide service | **System-wide service | ||
Ligne 32: | Ligne 58: | ||
Speaking of Gems, I needed to configure the environment variables to point to my .gem directory paths, otherwise the service failed to find the correct commands. Most articles I saw on this topic claimed that bash -lc would load the user’s shell profile (and therefore the variables), but that didn’t seem to be the case in ArchLinux. If you want to test to see if these lines are required on your machine, just delete them and check the output of your service through journalctl.** | Speaking of Gems, I needed to configure the environment variables to point to my .gem directory paths, otherwise the service failed to find the correct commands. Most articles I saw on this topic claimed that bash -lc would load the user’s shell profile (and therefore the variables), but that didn’t seem to be the case in ArchLinux. If you want to test to see if these lines are required on your machine, just delete them and check the output of your service through journalctl.** | ||
+ | |||
+ | Service à l' | ||
+ | |||
+ | Le fichier media-tracker.service que j'ai créé ressemble au code présenté ci-dessous. | ||
+ | |||
+ | Comme vous pouvez le voir, il y a quelques points importants dans ce fichier. D' | ||
+ | |||
+ | En parlant de Gems, j'ai besoin de configurer les variables d' | ||
**Lastly, I set the WorkingDirectory (path to my app files), and then ExecStart to run bundle exec rails server. | **Lastly, I set the WorkingDirectory (path to my app files), and then ExecStart to run bundle exec rails server. | ||
Ligne 44: | Ligne 78: | ||
To stop/ | To stop/ | ||
+ | |||
+ | Enfin, je paramètre WorkingDirectory (répertoire de travail - le chemin vers mes fichiers d' | ||
+ | |||
+ | Les autres options sont assez compréhensibles par elles-mêmes, | ||
+ | |||
+ | Copiez/ | ||
+ | |||
+ | sudo systemctl start media-tracker.service | ||
+ | |||
+ | sudo systemctl enable media-tracker.service | ||
+ | |||
+ | Pour arrêter/ | ||
**If you make changes to the service file, you may get a warning that the files need to be reloaded. To do that, run: | **If you make changes to the service file, you may get a warning that the files need to be reloaded. To do that, run: | ||
Ligne 60: | Ligne 106: | ||
The main difference between this and the system-wide service file is the missing “User” value.** | The main difference between this and the system-wide service file is the missing “User” value.** | ||
+ | |||
+ | Si vous faites des modifications dans le fichier du service, vous pourriez recevoir un avertissement disant que les fichiers doivent être rechargés. Pour ce faire, lancez : | ||
+ | |||
+ | sudo systemctl daemon-reload | ||
+ | |||
+ | Pour déboguer les problèmes, vous pouvez utiliser la commande suivante : | ||
+ | |||
+ | journalctl -u media-tracker | ||
+ | |||
+ | Remplacez media-tracker par le nom de fichier que vous avez choisi. | ||
+ | |||
+ | Fichier de service spécifique pour un utilisateur | ||
+ | |||
+ | Le fichier que j'ai créé pour un service spécifique à un utilisateur ressemble au code présenté ci-dessus. | ||
+ | |||
+ | La principale différence entre lui et le fichier service à l' | ||
**As I said in the section above (for anyone jumping directly to this section): | **As I said in the section above (for anyone jumping directly to this section): | ||
Ligne 66: | Ligne 128: | ||
3. The /bin/bash -lc should run the bash shell as a login shell, but, under ArchLinux, this doesn’t seem to fill the environment variables, hence why point 1 exists. | 3. The /bin/bash -lc should run the bash shell as a login shell, but, under ArchLinux, this doesn’t seem to fill the environment variables, hence why point 1 exists. | ||
4. The other options in the file are self-explanatory, | 4. The other options in the file are self-explanatory, | ||
+ | |||
+ | Comme je l'ai dit dans la section au-dessus (pour tous ceux qui sont passés directement à cette section) : | ||
+ | 1. Paramétrez les variables d' | ||
+ | 2. Réglez l' | ||
+ | 3. Le /bin/bash -lc devrait lancer le shell bash comme shell à la connexion, mais, sous ArchLinux, ça ne semble pas remplir les variables d' | ||
+ | 4. Les autres options dans le fichier se comprennent d' | ||
**Running the service | **Running the service | ||
Ligne 74: | Ligne 142: | ||
Note the lack of sudo, and the “--user” argument. The other commands are all of the same format - stop, enable, disable, and status. Just replace the word “start” with whatever option you need.** | Note the lack of sudo, and the “--user” argument. The other commands are all of the same format - stop, enable, disable, and status. Just replace the word “start” with whatever option you need.** | ||
+ | |||
+ | Faire tourner le service | ||
+ | |||
+ | Le lancement du service spécifique à un utilisateur est aussi facile que : | ||
+ | |||
+ | systemctl --user start media-tracker | ||
+ | |||
+ | Notez l' | ||
**Debug | **Debug | ||
In case your service fails to run, you can run journalctl --user -u media-tracker to get the output of your service.** | In case your service fails to run, you can run journalctl --user -u media-tracker to get the output of your service.** | ||
+ | |||
+ | Débogage | ||
+ | |||
+ | Au cas où votre service refuse de fonctionner, | ||
**Conclusion | **Conclusion | ||
I hope this article is useful for anyone who, like me, has a custom program they want to run on every login or boot. It seems like a lot of articles on topics like these focus on system-wide services, which is why I also included instructions for user-specific services. If you run into issues, or have improvements to offer me, feel free to send me an email at lswest34+fcm@gmail.com. Similarly, if you have any article requests, direct them to the same email address.** | I hope this article is useful for anyone who, like me, has a custom program they want to run on every login or boot. It seems like a lot of articles on topics like these focus on system-wide services, which is why I also included instructions for user-specific services. If you run into issues, or have improvements to offer me, feel free to send me an email at lswest34+fcm@gmail.com. Similarly, if you have any article requests, direct them to the same email address.** | ||
+ | |||
+ | Conclusion | ||
+ | |||
+ | J' | ||
Ligne 92: | Ligne 176: | ||
Pour aller plus loin | Pour aller plus loin | ||
- | https:// | + | https:// |
https:// | https:// |
issue145/c_c.1559597657.txt.gz · Dernière modification : 2019/06/03 23:34 de d52fr