issue145:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue145:c_c [2019/06/01 14:54] – créée auntiee | 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.** |
- | Notes | + | Un des programmes que j'ai écrits et que j' |
+ | |||
+ | **Notes | ||
This article will focus on getting a Rails app up and running through systemd. If you’re using something different, the broad strokes will be the same, but you may need to adjust more environment variables. | This article will focus on getting a Rails app up and running through systemd. If you’re using something different, the broad strokes will be the same, but you may need to adjust more environment variables. | ||
- | 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 |
First, you want to make note of where your program’s files are, and any paths you need to know (such as the $GEM_HOME and the relevant section of your $PATH). You can find these by simply running the following in your terminal of choice: | First, you want to make note of where your program’s files are, and any paths you need to know (such as the $GEM_HOME and the relevant section of your $PATH). You can find these by simply running the following in your terminal of choice: | ||
Ligne 14: | Ligne 22: | ||
echo $GEM_HOME | echo $GEM_HOME | ||
- | 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.** |
- | Decide - user or system service? | + | 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? | ||
Most modern systems have systemd set up to be run as both system, and a user-specific version. They are separate (and have separate folders they watch). The approach is similar for either one, but here are the main differences: | Most modern systems have systemd set up to be run as both system, and a user-specific version. They are separate (and have separate folders they watch). The approach is similar for either one, but here are the main differences: | ||
Ligne 23: | Ligne 40: | ||
2.User-based services also can’t be configured to run as another user (for example if you want to run Apache as an ‘html’ user or similar). Then you’ll need to use the system-wide version. | 2.User-based services also can’t be configured to run as another user (for example if you want to run Apache as an ‘html’ user or similar). Then you’ll need to use the system-wide version. | ||
- | 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.** |
- | System-wide service | + | À 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 | ||
The media-tracker.service file I created looks like the code shown below. | The media-tracker.service file I created looks like the code shown below. | ||
Ligne 31: | Ligne 57: | ||
As you can see, there are a few important aspects to this file. First, I set Type to “simple”, | As you can see, there are a few important aspects to this file. First, I set Type to “simple”, | ||
- | 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 |
+ | |||
+ | 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. |
The other options are relatively self-explanatory, | The other options are relatively self-explanatory, | ||
Ligne 43: | Ligne 77: | ||
sudo systemctl enable media-tracker.service | sudo systemctl enable media-tracker.service | ||
- | To stop/ | + | To stop/ |
- | If you make changes to the service file, you may get a warning that the files need to be reloaded. To do that, run: | + | 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: | ||
sudo systemctl daemon-reload | sudo systemctl daemon-reload | ||
Ligne 59: | Ligne 105: | ||
The file I created for a user-specific service looks like the code shown above. | The file I created for a user-specific service looks like the code shown above. | ||
- | 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.** |
- | As I said in the section above (for anyone jumping directly to this section): | + | 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): | ||
1. Set the environment variables you’ll need for this service. | 1. Set the environment variables you’ll need for this service. | ||
2. Set the WorkingDirectory option to the project folder. | 2. Set the WorkingDirectory option to the project folder. | ||
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, |
- | Running the service | + | 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 a user-specific service is as easy as: | Running a user-specific service is as easy as: | ||
Ligne 73: | Ligne 141: | ||
systemctl --user start media-tracker | systemctl --user start media-tracker | ||
- | 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.** |
- | Debug | + | Faire tourner le service |
- | In case your service | + | |
- | Conclusion | + | Le lancement du service spécifique à un utilisateur est aussi facile que : |
- | 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. | + | systemctl --user start media-tracker |
+ | Notez l' | ||
+ | **Debug | ||
+ | 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 | ||
+ | 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' | ||
+ | **Further Reading | ||
+ | https:// | ||
+ | https:// | ||
+ | Pour aller plus loin | ||
+ | https:// | ||
- | Further Reading | + | https:// |
- | + | ||
- | https:// | + | |
- | + | ||
- | https:// | + |
issue145/c_c.1559393643.txt.gz · Dernière modification : 2019/06/01 14:54 de auntiee