Fri Jan 12, 2018 4:03 pm
Thanks for the reply. The service versus socket scenario was something I found in one of the various examples, that looking interesting, but it complicated the issue. What I wanted to do was to have each rails application use a different port, this is all development level work, but would let me isolate traffic per port with ease, for analysis.
You are correct, the working directory should be qualified, and I agree adding Standard*/Syslog is a good idea. Last night, after some serious isolation differences and comparison of examples, I got a simple variant working. The sample below works, and it is the minimum, I still need to incorporate some of the suggestions you noted, I will do that and post and update version soon. But for those that may find this interesting, here is what is working for now now.
# cat /etc/systemd/system/demo.service
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/rails/demo
ExecStart=/bin/bash -lc 'bundle exec puma -C /home/rails/demo/config/puma.rb'
User=rails
Restart=always
[Install]
WantedBy=multi-user.target
I change the default port in the config/puma.rb script, per application, so demo is 3000, hello is 3001, etc. for example. Long term, I will set the rails applications to a production comparable environment, where I plan to use environment variables to control the port assignment, but I am still learning rails, so this is sufficient for now.
# cat /home/rails/demo/config/puma.rb | grep PORT
port ENV.fetch("PORT") { 3000 }
# cat /home/rails/hello/config/puma.rb | grep PORT
port ENV.fetch("PORT") { 3001 }
What is interesting is that their are so many variants to invoking the rails server to execute the application, the examples vary even within the same OS, distribution, etc. This has always been what I consider good and bad about Linux, to many ways to do the same thing. Having also been a engineer/designer/programmer on Macintosh and Windows, where the variance is less, ah, diverse? But I digress.
I will post a more detailed unit file with the suggestions you noted soon as I noted above.