Skip to content

Commit 5656483

Browse files
committed
Fix an issue in 'watch' and 'preview' where main process is terminated with child processes still running
1 parent 04973e0 commit 5656483

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Rakefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ task :watch do
6060
compassPid = Process.spawn("compass watch")
6161

6262
trap("INT") {
63-
Process.kill(9, jekyllPid)
64-
Process.kill(9, compassPid)
65-
exit 0
63+
[jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
64+
exit 0
6665
}
6766

68-
Process.wait
67+
[jekyllPid, compassPid].each { |pid| Process.wait(pid) }
6968
end
7069

7170
desc "preview the site in a web browser"
@@ -77,13 +76,11 @@ task :preview do
7776
rackupPid = Process.spawn("rackup --port #{server_port}")
7877

7978
trap("INT") {
80-
Process.kill(9, jekyllPid)
81-
Process.kill(9, compassPid)
82-
Process.kill(9, rackupPid)
83-
exit 0
79+
[jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
80+
exit 0
8481
}
8582

86-
Process.wait
83+
[jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
8784
end
8885

8986
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")

0 commit comments

Comments
 (0)