ysbaddaden / prax

Rack proxy server for development
http://ysbaddaden.github.io/prax/
Other
475 stars 49 forks source link

Systemd support? #45

Closed rikai closed 9 years ago

rikai commented 10 years ago

Was just trying to install Prax on Arch and realized that currently it is init based. Luckily someone awesome seems to have done the minor legwork it takes to use it with systemd.

Perhaps this can be implemented upstream?

As a sidenote, prax seems to be working flawlessly on ruby 2.0.0p247! :+1:

terlar commented 10 years ago

Yeah, that only adds the firewall rule however, would be nice to also control the start/restart of actual prax also through systemd. But seems that is not systemd specific issue as it is suggested to run prax by going to the dir and running ./bin/prax.

Also thanks again for prax, works very well :)

yachi commented 10 years ago

+1

ysbaddaden commented 10 years ago

I'd sure like to support systemd and archlinux! Do you have a mean to detect which I should install and setup?

Notes:

yachi commented 10 years ago

how can i start prax as a normal user? any example? the default install script is doing too many scary root stuff

ysbaddaden commented 10 years ago

There are some sudos, because they can't be installed as user.

You may install something else, like dnsmasq, to resolve .dev domains; and you may skip the port redirection, if you don't mind having to specify :20559 in your URL. Or you may install those manually, just follow the libexec/prax-install script :)

terlar commented 10 years ago

Yes, the IP-tables stuff needs to be done by root and that is exactly what is done in my gist.

/usr/lib/systemd/system/prax.service

[Unit]
Description=Prax Rack server (iptables configuration)
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/praxd start
ExecStop=/usr/local/bin/praxd stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then the install script just have to put that file in the refered location. (praxd is the script adding the ip-tables rules)

However if you show an example of the best practice to start prax "globally" for a user I can create the corresponding systemd --user file.

I have had troubles launching prax though, always have to cd to the dir and execute it ./bin/prax start. Also it only works with projects using the same ruby as I ran it with.

What am I doing wrong, I can easily create the systemd file if we solve this.

ysbaddaden commented 10 years ago

Starting prax requires bash, to get the correct install dir and a clean environment, not yet modified by version managers.

Then Prax will spawn the apps running bundle or ruby from the project directory, using a fully cleaned up shell environment (only keeping the original PATH). It makes using different ruby versions possible. It works with rbenv at least.

To start prax globally as a user, you may have to add the necessary shell things of your version manager in your ~/.praxconfig which is sourced when Prax is started, otherwise ruby might not be found, or not be the expected ruby (no shell login).

A fix for version managers could be foe Prax::Spawner to source ~/.praxconfig again, so the correct version could be found.

J.

terlar commented 10 years ago

Yes, I would like ~/.praxconfig to be sourced again, preferably acting like it was executed from the project directory for the project it's spawning, so the executed commands do the expected thing.

With the current setup I can do something like this (the WorkingDirectory should not be needed, but I use it to control which ruby prax gets executed with.):

~/.config/systemd/user/prax.service

[Unit]
Description=Prax
After=network.target
Requires=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/USERNAME/.prax-dist/bin/prax start
ExecStop=/home/USERNAME/.prax-dist/bin/prax stop
WorkingDirectory=/home/USERNAME/.prax-dist

[Install]
WantedBy=default.target

Then I start and stop prax like this:

systemctl --user start prax
systemctl --user stop prax
ysbaddaden commented 9 years ago

Closing, since Prax MUST be run by the current logged in user. I use a prax.desktop file in ~/.config/autostart that GNOME and Unity are launching when I log in, for instance.

Please create a distribution package for your distro, or create an "install on systemd" page on the wiki.