jacobobryant / platypub

A publishing platform built with Biff
MIT License
65 stars 13 forks source link

Cleanly shutting down after using ./task dev #76

Closed michaeleverson closed 1 year ago

michaeleverson commented 2 years ago

Hi,

Great project.

I might be missing something, but what is the best way to shutdown all the processes cleanly after using ./task dev ?

I'm running Platypub locally on my Mac.

If I use ctrl-d there still seems to be something leftover listening on a port and lock files in the db folder that prevents restarting ./task dev (unless I log out / in of my computer).

I can't seem to find a shutdown function in the Clojure code. I tweaked the refresh function to make a shutdown function, which resolved the lock file issue, but the port issue remained (I still had to ctrl-d in the terminal).

Just wondering if I'm doing something incorrectly, or whether I should dig deeper?

jacobobryant commented 2 years ago

Does ctrl-c work? That's what I always do on linux.

I wonder if the strange behavior is related to running the jvm in the background: https://github.com/jacobobryant/platypub/blob/master/task#L38-L39. If needed that could be restructured.

michaeleverson commented 2 years ago

Ctrl-c has the same behaviour. I will play around more with it after work today.

jacobobryant commented 2 years ago

interesting. Could you edit ./task so the dev function runs the JVM in the foreground and then see if you get the same behavior from ctrl-d / ctrl-c:

dev () {
  echo $PORT > .nrepl-port
  BIFF_ENV=dev run
  #css --watch
}
michaeleverson commented 2 years ago

No worries.

I did the edit and now ./task dev can be ctrl+c-ed and relaunched without an error getting in the way (ctrl+d now does nothing, for whatever reason).

jacobobryant commented 2 years ago

OK, that's good to hear. I'll update platypub then to get rid of the background jvm thing. in the mean time you can run ./task dev as it is now, and run ./task css --watch in a separate terminal to handle css updates.

I'm guessing the ctrl-d thing is due to some difference between jvm and node 🤷. Maybe tailwind watches stdin. just curious, are you normally able to close other Clojure projects with ctrl-d (in which case maybe I've done something abnormal with Biff)?

On Mon, Sep 26, 2022, at 7:49 PM, Michael Everson wrote:

No worries.

I did the edit and now ./task dev can be ctrl+c-ed and relaunched without an error getting in the way (ctrl+d now does nothing, for whatever reason).

— Reply to this email directly, view it on GitHub https://github.com/jacobobryant/platypub/issues/76#issuecomment-1258894993, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4GPWRDNUNF2ICCM6RSJ33WAJODTANCNFSM6AAAAAAQWG5OYQ. You are receiving this because you commented.Message ID: @.***>

michaeleverson commented 2 years ago

I'm used to using ctrl-d to exit other Clojure projects I've worked on, but I admit for those I've been using them within lein, shadow-clj or even the clj tool directly rather than coordinated via a shell script - so there might be something there? (I had one with tailwind.css, but since I added it myself and was lazy, I always just had it monitoring in another tab). I think the shell script is cool though :)

jacobobryant commented 2 years ago

Oh actually now that I think about it, I'm guessing usually lein etc are opening an interactive prompt when you run them? That would explain why ctrl-d causes the program to end, since it's sending an end-of-document signal and the prompt closes when stdin is closed. whereas with Biff I've made it so the only way to interact with the REPL is via your editor, and it doesn't do anything with stdin. It's been so long I had forgotten about that :).

michaeleverson commented 2 years ago

Yes, I think you're probably right. It's been a happy accident with the ctrl-d business :)

jacobobryant commented 2 years ago

I figured out how to make the css --watch command run in the background, and I've just pushed a commit which does so and has the jvm run in the foreground. Can you pull that and check if ctrl-c now closes everything correctly?

michaeleverson commented 1 year ago

I've checked it out and the change seems to have fixed the issue. Much appreciated and I'm glad I flagged it :)