2

I'm trying to write a script that launches Jekyll from the command line, does another process, and then stops it.

The logic would be like this:

  1. start jekyll serve.
  2. run a process called Prince to build a PDF from the HTML files.
  3. stop the jekyll server.

I'm not very experienced with the command line. I think I have to use the --detach command with Jekyll to continue running scripts after the preview server builds. But then if I detach Jekyll, the only way to stop the server is by killing a specific PID, but the PID number seems to be generated randomly.

Anyone have any tips on how to construct this script?

Tom Johnson
  • 729
  • 8
  • 17
  • 1
    Cannot you just do `jekyll build` instead of `jekyll serve` ? – Thilo Apr 22 '15 at 22:40
  • 1
    after i run `jekyll serve`, i need to run princexml, which will look for a collection of html pages to consolidate into a PDF. princexml seems to require the html pages to be crawlable, so if the site is not available at the preview link (http://127.0.0.1/), prince has trouble finding the pages. – Tom Johnson Apr 23 '15 at 02:59

3 Answers3

8

If you don't know the PID, you can do :

kill $(ps aux | grep '[j]ekyll' | awk '{print $2}')

See explanations here

Community
  • 1
  • 1
David Jacquel
  • 51,670
  • 6
  • 121
  • 147
  • Thanks, but it's not quite working. The problem is that as soon as the server detaches, it can't proceed to the next command. Instead I get this message: ``` tjohnson-mbpr13:acme tjohnson$ E, [2015-04-23T17:01:08.179397 #85057] ERROR -- : Couldn't cleanly terminate all actors in 10 seconds! ``` – Tom Johnson Apr 24 '15 at 00:17
  • I'm not sure why, but every time I hit the Return key, the site activates the Add Comment button, and doesn't allow me to add any paragraph spacing. – Tom Johnson Apr 24 '15 at 00:19
  • I had to add the -9 flag to get this to work: `kill -9 $(ps aux | grep '[j]ekyll' | awk '{print $2}') ` – Ari Anisfeld Feb 08 '22 at 03:36
0

Another way to stop the Jekyll process (without PID)

pkill -f jekyll
Nicolas Pennec
  • 7,533
  • 29
  • 43
-1

In OS X, you can issue

killall jekyll

I put this into a grunt-shell task. The remaining issue is that neither kill nor killall seem to have a --quiet setting. If it would run with no return code or message, then that shell:jekyllStop grunt task could be the first step in my default. If jekyll happens not to be running, default stops/fails. You can get grunt to continue using --force, but that argument would apply to all tasks.

shell: {
  jekyllStop: {
    command: "killall jekyll"
  }
},

Running "shell:jekyllStop" (shell) task No matching processes belonging to you were found Warning: Command failed: No matching processes belonging to you were found Use --force to continue.

Aborted due to warnings.

Process finished with exit code 6

Monte Hayward
  • 459
  • 2
  • 11