├── .gitignore ├── .tool-versions ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── SYSTEMD.md ├── capistrano-sidekiq.gemspec └── lib ├── capistrano-sidekiq.rb └── capistrano ├── sidekiq.rb ├── sidekiq ├── systemd.rb └── version.rb ├── tasks ├── sidekiq.rake └── systemd.rake └── templates └── sidekiq.service.capistrano.erb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | .idea 19 | *.iml -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 3.4.1 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [Unreleased](https://github.com/seuros/capistrano-sidekiq/compare/v2.3.0...master) 4 | - Rewrite to match capistrano3-puma api 5 | - Add support for multiple sidekiq configs (processes and queues can be configured with erb) 6 | - Add support to multiple EnvironmentFile 7 | - Add support to multiple EnvironmentVariables 8 | - Default role for sidekiq is now :worker instead of :app 9 | 10 | ## [2.3.0](https://github.com/seuros/capistrano-sidekiq/tree/2.3.0) (2022-05-17) 11 | 12 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.2.0...2.3.0) 13 | 14 | **Merged pull requests:** 15 | 16 | - fix sidekiq processes naming when count is 1 [\#300](https://github.com/seuros/capistrano-sidekiq/pull/300) ([seuros](https://github.com/seuros)) 17 | - Support multiple processes in `sidekiq:install` [\#299](https://github.com/seuros/capistrano-sidekiq/pull/299) ([lloydwatkin](https://github.com/lloydwatkin)) 18 | - fix: monit config template [\#288](https://github.com/seuros/capistrano-sidekiq/pull/288) ([jpickwell](https://github.com/jpickwell)) 19 | 20 | ## [v2.2.0](https://github.com/seuros/capistrano-sidekiq/tree/v2.2.0) (2022-05-16) 21 | 22 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.1.0...v2.2.0) 23 | 24 | **Merged pull requests:** 25 | 26 | - Allow the definition of service\_unit\_name [\#297](https://github.com/seuros/capistrano-sidekiq/pull/297) ([seuros](https://github.com/seuros)) 27 | - restore sidekiq unit env vars [\#295](https://github.com/seuros/capistrano-sidekiq/pull/295) ([tayagi-aim](https://github.com/tayagi-aim)) 28 | - Fix a typo in sidekiq:restart [\#294](https://github.com/seuros/capistrano-sidekiq/pull/294) ([hoppergee](https://github.com/hoppergee)) 29 | 30 | ## [v2.1.0](https://github.com/seuros/capistrano-sidekiq/tree/v2.1.0) (2022-05-15) 31 | 32 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0...v2.1.0) 33 | 34 | **Merged pull requests:** 35 | 36 | - Fix \#253: $HOME is unexpanded in service unit file [\#291](https://github.com/seuros/capistrano-sidekiq/pull/291) ([nikochiko](https://github.com/nikochiko)) 37 | - Update Readme [\#287](https://github.com/seuros/capistrano-sidekiq/pull/287) ([lesliepoolman](https://github.com/lesliepoolman)) 38 | - Fixed sidekiq.service autostart in --user mode [\#285](https://github.com/seuros/capistrano-sidekiq/pull/285) ([michaelkhabarov](https://github.com/michaelkhabarov)) 39 | - README: Add section about older Systemd versions logging [\#284](https://github.com/seuros/capistrano-sidekiq/pull/284) ([64kramsystem](https://github.com/64kramsystem)) 40 | - Avoid using present? [\#282](https://github.com/seuros/capistrano-sidekiq/pull/282) ([frederikspang](https://github.com/frederikspang)) 41 | - Various systemd improvements - Multiple Process Support, Per Process Config, Proper Restarts with timeout and more [\#279](https://github.com/seuros/capistrano-sidekiq/pull/279) ([jclusso](https://github.com/jclusso)) 42 | - Use File.join for systemd file path [\#278](https://github.com/seuros/capistrano-sidekiq/pull/278) ([AndrewSverdrup](https://github.com/AndrewSverdrup)) 43 | - Fix bug in switch\_user and dry up common methods to a helpers module [\#272](https://github.com/seuros/capistrano-sidekiq/pull/272) ([chriscz](https://github.com/chriscz)) 44 | - Update monit integration against Sidekiq 6.0 [\#271](https://github.com/seuros/capistrano-sidekiq/pull/271) ([7up4](https://github.com/7up4)) 45 | - Added sidekiq\_service\_templates\_path to manage custom systemd templates [\#265](https://github.com/seuros/capistrano-sidekiq/pull/265) ([farnsworth](https://github.com/farnsworth)) 46 | - Add sidekiq\_config, sidekiq\_concurrency, and sidekiq\_queue support to systemd [\#262](https://github.com/seuros/capistrano-sidekiq/pull/262) ([ayn](https://github.com/ayn)) 47 | 48 | ## [v2.0.0](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0) (2020-12-19) 49 | 50 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0.beta5...v2.0.0) 51 | 52 | **Merged pull requests:** 53 | 54 | - Upstart update [\#261](https://github.com/seuros/capistrano-sidekiq/pull/261) ([duhast](https://github.com/duhast)) 55 | 56 | ## [v2.0.0.beta5](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0.beta5) (2020-06-25) 57 | 58 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0.beta4...v2.0.0.beta5) 59 | 60 | **Merged pull requests:** 61 | 62 | - Minimal working Upstart plugin [\#255](https://github.com/seuros/capistrano-sidekiq/pull/255) ([duhast](https://github.com/duhast)) 63 | - Capistrano rbenv uses bundle instead of bundler [\#252](https://github.com/seuros/capistrano-sidekiq/pull/252) ([uxxman](https://github.com/uxxman)) 64 | 65 | ## [v2.0.0.beta4](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0.beta4) (2020-06-08) 66 | 67 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0.beta3...v2.0.0.beta4) 68 | 69 | **Merged pull requests:** 70 | 71 | - Fix undefined method as error [\#249](https://github.com/seuros/capistrano-sidekiq/pull/249) ([kyoshidajp](https://github.com/kyoshidajp)) 72 | 73 | ## [v2.0.0.beta3](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0.beta3) (2020-05-26) 74 | 75 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0.beta2...v2.0.0.beta3) 76 | 77 | **Merged pull requests:** 78 | 79 | - Append logs [\#247](https://github.com/seuros/capistrano-sidekiq/pull/247) ([Paprikas](https://github.com/Paprikas)) 80 | - Add "loginctl enable-linger" command to sidekiq systemd install task [\#246](https://github.com/seuros/capistrano-sidekiq/pull/246) ([Paprikas](https://github.com/Paprikas)) 81 | - Setup error output for systemd [\#245](https://github.com/seuros/capistrano-sidekiq/pull/245) ([Paprikas](https://github.com/Paprikas)) 82 | - Use StandardOutput for logging [\#244](https://github.com/seuros/capistrano-sidekiq/pull/244) ([Paprikas](https://github.com/Paprikas)) 83 | 84 | ## [v2.0.0.beta2](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0.beta2) (2020-05-25) 85 | 86 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.0.0.beta1...v2.0.0.beta2) 87 | 88 | **Merged pull requests:** 89 | 90 | - Add sidekiq\_service\_unit\_env\_vars option to pass Environment variable… [\#243](https://github.com/seuros/capistrano-sidekiq/pull/243) ([Paprikas](https://github.com/Paprikas)) 91 | 92 | ## [v2.0.0.beta1](https://github.com/seuros/capistrano-sidekiq/tree/v2.0.0.beta1) (2020-05-12) 93 | 94 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v1.0.3...v2.0.0.beta1) 95 | 96 | **Merged pull requests:** 97 | 98 | - Release 2.0.0 [\#236](https://github.com/seuros/capistrano-sidekiq/pull/236) ([seuros](https://github.com/seuros)) 99 | 100 | ## [v1.0.3](https://github.com/seuros/capistrano-sidekiq/tree/v1.0.3) (2019-09-02) 101 | 102 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v1.0.2...v1.0.3) 103 | 104 | **Merged pull requests:** 105 | 106 | - Point readers towards enable lingering for systemd [\#230](https://github.com/seuros/capistrano-sidekiq/pull/230) ([creativetags](https://github.com/creativetags)) 107 | - Update README\#Multiple processes example [\#215](https://github.com/seuros/capistrano-sidekiq/pull/215) ([tamaloa](https://github.com/tamaloa)) 108 | - Add upstart support for start, stop, and quiet [\#208](https://github.com/seuros/capistrano-sidekiq/pull/208) ([tmiller](https://github.com/tmiller)) 109 | - Fix monit config file name missing application [\#205](https://github.com/seuros/capistrano-sidekiq/pull/205) ([xiewenwei](https://github.com/xiewenwei)) 110 | 111 | ## [v1.0.2](https://github.com/seuros/capistrano-sidekiq/tree/v1.0.2) (2018-04-12) 112 | 113 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v1.0.1...v1.0.2) 114 | 115 | ## [v1.0.1](https://github.com/seuros/capistrano-sidekiq/tree/v1.0.1) (2018-04-04) 116 | 117 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v1.0.0...v1.0.1) 118 | 119 | **Merged pull requests:** 120 | 121 | - Fix accounting of pidfiles per process \(when using multiple processes\) [\#197](https://github.com/seuros/capistrano-sidekiq/pull/197) ([jsantos](https://github.com/jsantos)) 122 | - fix fail rolling restart task [\#196](https://github.com/seuros/capistrano-sidekiq/pull/196) ([idekeita](https://github.com/idekeita)) 123 | - README.md - simple edit, highlight known issue with cap 3 [\#192](https://github.com/seuros/capistrano-sidekiq/pull/192) ([westonplatter](https://github.com/westonplatter)) 124 | - Systemd integration [\#171](https://github.com/seuros/capistrano-sidekiq/pull/171) ([baierjan](https://github.com/baierjan)) 125 | - update README with instructions for prepending 'bundle exec' [\#143](https://github.com/seuros/capistrano-sidekiq/pull/143) ([mistidoi](https://github.com/mistidoi)) 126 | - Add deploy failure handling to cap v2 and v3. [\#135](https://github.com/seuros/capistrano-sidekiq/pull/135) ([phillbaker](https://github.com/phillbaker)) 127 | - Support custom monit filename [\#132](https://github.com/seuros/capistrano-sidekiq/pull/132) ([zocoi](https://github.com/zocoi)) 128 | 129 | ## [v1.0.0](https://github.com/seuros/capistrano-sidekiq/tree/v1.0.0) (2018-01-24) 130 | 131 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.20.0...v1.0.0) 132 | 133 | **Merged pull requests:** 134 | 135 | - Spring Cleanup [\#190](https://github.com/seuros/capistrano-sidekiq/pull/190) ([Tensho](https://github.com/Tensho)) 136 | - Convert CHANGELOG to Markdown + Add Unreleased Section [\#189](https://github.com/seuros/capistrano-sidekiq/pull/189) ([Tensho](https://github.com/Tensho)) 137 | - Prepend \_ Before Service Name Index [\#184](https://github.com/seuros/capistrano-sidekiq/pull/184) ([Tensho](https://github.com/Tensho)) 138 | - Christmas Eve Cleaning 🎅 [\#183](https://github.com/seuros/capistrano-sidekiq/pull/183) ([Tensho](https://github.com/Tensho)) 139 | 140 | ## [v0.20.0](https://github.com/seuros/capistrano-sidekiq/tree/v0.20.0) (2017-08-01) 141 | 142 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.10.0...v0.20.0) 143 | 144 | **Merged pull requests:** 145 | 146 | - Use new capistrano DSL for reenable tasks [\#177](https://github.com/seuros/capistrano-sidekiq/pull/177) ([Tensho](https://github.com/Tensho)) 147 | 148 | ## [v0.10.0](https://github.com/seuros/capistrano-sidekiq/tree/v0.10.0) (2016-11-25) 149 | 150 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.5.4...v0.10.0) 151 | 152 | **Merged pull requests:** 153 | 154 | - add documentation; add note to ensure shared/tmp/pids folder exists i… [\#168](https://github.com/seuros/capistrano-sidekiq/pull/168) ([elliotwesoff](https://github.com/elliotwesoff)) 155 | - Make sidekiq:stop task perpetually callable [\#164](https://github.com/seuros/capistrano-sidekiq/pull/164) ([williamn](https://github.com/williamn)) 156 | - Add missing monit default config options to README [\#155](https://github.com/seuros/capistrano-sidekiq/pull/155) ([kirrmann](https://github.com/kirrmann)) 157 | - Documenting sidekiq\_service\_name config option [\#153](https://github.com/seuros/capistrano-sidekiq/pull/153) ([bendilley](https://github.com/bendilley)) 158 | - Fixes identation and Increase documentation with info about :sidekiq\_config [\#131](https://github.com/seuros/capistrano-sidekiq/pull/131) ([ricardokdz](https://github.com/ricardokdz)) 159 | - Respect both local and global puma\_user setting everywhere [\#122](https://github.com/seuros/capistrano-sidekiq/pull/122) ([jhollinger](https://github.com/jhollinger)) 160 | 161 | ## [v0.5.4](https://github.com/seuros/capistrano-sidekiq/tree/v0.5.4) (2015-10-27) 162 | 163 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.5.3...v0.5.4) 164 | 165 | **Merged pull requests:** 166 | 167 | - Change pidfile handling, always add index to pidfile name [\#116](https://github.com/seuros/capistrano-sidekiq/pull/116) ([w1mvy](https://github.com/w1mvy)) 168 | - Move Contributors to separate file. [\#115](https://github.com/seuros/capistrano-sidekiq/pull/115) ([lpaulmp](https://github.com/lpaulmp)) 169 | - Monit configuration respects options\_per\_process [\#113](https://github.com/seuros/capistrano-sidekiq/pull/113) ([kazjote](https://github.com/kazjote)) 170 | - Capistrano 2 fixes [\#109](https://github.com/seuros/capistrano-sidekiq/pull/109) ([wingrunr21](https://github.com/wingrunr21)) 171 | - Use SSHKit command\_map [\#104](https://github.com/seuros/capistrano-sidekiq/pull/104) ([hbin](https://github.com/hbin)) 172 | - Add notice that the pty bug only applies to Capistrano 3. [\#101](https://github.com/seuros/capistrano-sidekiq/pull/101) ([nTraum](https://github.com/nTraum)) 173 | - Add support for different number of processes per host on monit.cap [\#100](https://github.com/seuros/capistrano-sidekiq/pull/100) ([okoriko](https://github.com/okoriko)) 174 | - intial support for sidekiq\_user [\#97](https://github.com/seuros/capistrano-sidekiq/pull/97) ([mcb](https://github.com/mcb)) 175 | 176 | ## [v0.5.3](https://github.com/seuros/capistrano-sidekiq/tree/v0.5.3) (2015-06-25) 177 | 178 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.5.2...v0.5.3) 179 | 180 | **Merged pull requests:** 181 | 182 | - Refactored template\_sidekiq method [\#90](https://github.com/seuros/capistrano-sidekiq/pull/90) ([rstrobl](https://github.com/rstrobl)) 183 | - added ability to operate without sudo [\#89](https://github.com/seuros/capistrano-sidekiq/pull/89) ([dreyks](https://github.com/dreyks)) 184 | - Revert "Add nohup when executing start\_sidekiq command, for a problem… [\#88](https://github.com/seuros/capistrano-sidekiq/pull/88) ([seuros](https://github.com/seuros)) 185 | - Add nohup when executing start\_sidekiq command, for a problem with pty. [\#76](https://github.com/seuros/capistrano-sidekiq/pull/76) ([maruware](https://github.com/maruware)) 186 | - implemented ability to split sidekiq\_roles by count of sidekiq-processes [\#45](https://github.com/seuros/capistrano-sidekiq/pull/45) ([alexyakubenko](https://github.com/alexyakubenko)) 187 | 188 | ## [v0.5.2](https://github.com/seuros/capistrano-sidekiq/tree/v0.5.2) (2015-03-20) 189 | 190 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.5.1...v0.5.2) 191 | 192 | **Merged pull requests:** 193 | 194 | - Set sidekiq\_concurrency default value for cap 2 \(improves pr \#72\). [\#74](https://github.com/seuros/capistrano-sidekiq/pull/74) ([derSascha](https://github.com/derSascha)) 195 | 196 | ## [v0.5.1](https://github.com/seuros/capistrano-sidekiq/tree/v0.5.1) (2015-03-18) 197 | 198 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.5.0...v0.5.1) 199 | 200 | **Merged pull requests:** 201 | 202 | - Support sidekiq\_concurrency option for capistrano 2 [\#72](https://github.com/seuros/capistrano-sidekiq/pull/72) ([mrsimo](https://github.com/mrsimo)) 203 | 204 | ## [v0.5.0](https://github.com/seuros/capistrano-sidekiq/tree/v0.5.0) (2015-03-18) 205 | 206 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.4.0...v0.5.0) 207 | 208 | **Merged pull requests:** 209 | 210 | - Options per process [\#70](https://github.com/seuros/capistrano-sidekiq/pull/70) ([mrsimo](https://github.com/mrsimo)) 211 | - Try execute on the monit.conf mv command [\#69](https://github.com/seuros/capistrano-sidekiq/pull/69) ([bencrouse](https://github.com/bencrouse)) 212 | - Update sidekiq.cap [\#68](https://github.com/seuros/capistrano-sidekiq/pull/68) ([raulbrito](https://github.com/raulbrito)) 213 | - bug fix for generator. [\#66](https://github.com/seuros/capistrano-sidekiq/pull/66) ([zshannon](https://github.com/zshannon)) 214 | - Fix Readme Issues [\#63](https://github.com/seuros/capistrano-sidekiq/pull/63) ([ChuckJHardy](https://github.com/ChuckJHardy)) 215 | - Set default option for sidekiq queue in capistrano 2 script [\#62](https://github.com/seuros/capistrano-sidekiq/pull/62) ([brain-geek](https://github.com/brain-geek)) 216 | - Update Cap2 Defaults to include config file [\#61](https://github.com/seuros/capistrano-sidekiq/pull/61) ([davidlesches](https://github.com/davidlesches)) 217 | - add customizing the monit templates for sidekiq [\#60](https://github.com/seuros/capistrano-sidekiq/pull/60) ([SammyLin](https://github.com/SammyLin)) 218 | - Add queues setup in capistrano2 task [\#57](https://github.com/seuros/capistrano-sidekiq/pull/57) ([brain-geek](https://github.com/brain-geek)) 219 | 220 | ## [v0.4.0](https://github.com/seuros/capistrano-sidekiq/tree/v0.4.0) (2014-11-12) 221 | 222 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.3.8...v0.4.0) 223 | 224 | **Merged pull requests:** 225 | 226 | - Test is Sidekiq actually running when starting with Capistrano 2 [\#54](https://github.com/seuros/capistrano-sidekiq/pull/54) ([Envek](https://github.com/Envek)) 227 | - use release\_path instead of current\_path [\#50](https://github.com/seuros/capistrano-sidekiq/pull/50) ([flyerhzm](https://github.com/flyerhzm)) 228 | - Typo [\#48](https://github.com/seuros/capistrano-sidekiq/pull/48) ([binyamindavid](https://github.com/binyamindavid)) 229 | - Fix descriptions of monit tasks [\#47](https://github.com/seuros/capistrano-sidekiq/pull/47) ([jgeiger](https://github.com/jgeiger)) 230 | 231 | ## [v0.3.8](https://github.com/seuros/capistrano-sidekiq/tree/v0.3.8) (2014-09-22) 232 | 233 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.3.7...v0.3.8) 234 | 235 | **Merged pull requests:** 236 | 237 | - Improve @bensie pull request + unmonitor monit while deploy [\#46](https://github.com/seuros/capistrano-sidekiq/pull/46) ([Saicheg](https://github.com/Saicheg)) 238 | 239 | ## [v0.3.7](https://github.com/seuros/capistrano-sidekiq/tree/v0.3.7) (2014-09-01) 240 | 241 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.3.6...v0.3.7) 242 | 243 | **Merged pull requests:** 244 | 245 | - Start Sidekiq as daemon from Monit [\#40](https://github.com/seuros/capistrano-sidekiq/pull/40) ([dpaluy](https://github.com/dpaluy)) 246 | - Sidekiq is properly restarted after a crash when deploying with Capsitrano2 [\#39](https://github.com/seuros/capistrano-sidekiq/pull/39) ([tribble](https://github.com/tribble)) 247 | 248 | ## [v0.3.6](https://github.com/seuros/capistrano-sidekiq/tree/v0.3.6) (2014-08-08) 249 | 250 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.3.5...v0.3.6) 251 | 252 | **Merged pull requests:** 253 | 254 | - If :sidekiq\_config is set, Monit template should use it to start the ser... [\#35](https://github.com/seuros/capistrano-sidekiq/pull/35) ([joshmyers](https://github.com/joshmyers)) 255 | - replace deploy:restart with deploy:publishing for capistrano 3.1 [\#34](https://github.com/seuros/capistrano-sidekiq/pull/34) ([flyerhzm](https://github.com/flyerhzm)) 256 | - Fix: test with spaces ignores within [\#33](https://github.com/seuros/capistrano-sidekiq/pull/33) ([rogercampos](https://github.com/rogercampos)) 257 | - Added \_cset for :sidekiq\_tag [\#32](https://github.com/seuros/capistrano-sidekiq/pull/32) ([OscarBarrett](https://github.com/OscarBarrett)) 258 | 259 | ## [v0.3.5](https://github.com/seuros/capistrano-sidekiq/tree/v0.3.5) (2014-07-25) 260 | 261 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.3.4...v0.3.5) 262 | 263 | **Merged pull requests:** 264 | 265 | - Allow use of sidekiq\_tag for capistrano2 [\#30](https://github.com/seuros/capistrano-sidekiq/pull/30) ([OscarBarrett](https://github.com/OscarBarrett)) 266 | 267 | ## [v0.3.4](https://github.com/seuros/capistrano-sidekiq/tree/v0.3.4) (2014-07-09) 268 | 269 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v0.1.0...v0.3.4) 270 | 271 | **Merged pull requests:** 272 | 273 | - Added concurrency option [\#26](https://github.com/seuros/capistrano-sidekiq/pull/26) ([ungsophy](https://github.com/ungsophy)) 274 | - Fix bug with process index in monit task [\#21](https://github.com/seuros/capistrano-sidekiq/pull/21) ([0x616E676572](https://github.com/0x616E676572)) 275 | - You can now use signals to quiet/stop sidekiq, much faster. [\#18](https://github.com/seuros/capistrano-sidekiq/pull/18) ([penso](https://github.com/penso)) 276 | - Check that current\_path exists before stopping [\#16](https://github.com/seuros/capistrano-sidekiq/pull/16) ([alexdunae](https://github.com/alexdunae)) 277 | - search pid files in correct directory [\#12](https://github.com/seuros/capistrano-sidekiq/pull/12) ([levinalex](https://github.com/levinalex)) 278 | - Rolling restart [\#7](https://github.com/seuros/capistrano-sidekiq/pull/7) ([jlecour](https://github.com/jlecour)) 279 | 280 | ## [v0.1.0](https://github.com/seuros/capistrano-sidekiq/tree/v0.1.0) (2014-03-24) 281 | 282 | [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/07b9d97f5bcf08af43baec0924bb088a6486f31c...v0.1.0) 283 | 284 | **Merged pull requests:** 285 | 286 | - Cleaner version checking [\#6](https://github.com/seuros/capistrano-sidekiq/pull/6) ([ghost](https://github.com/ghost)) 287 | - More robust version checking [\#4](https://github.com/seuros/capistrano-sidekiq/pull/4) ([jlecour](https://github.com/jlecour)) 288 | - More explicit start command [\#3](https://github.com/seuros/capistrano-sidekiq/pull/3) ([jlecour](https://github.com/jlecour)) 289 | - Improve pid and log files settings [\#1](https://github.com/seuros/capistrano-sidekiq/pull/1) ([jlecour](https://github.com/jlecour)) 290 | 291 | 292 | 293 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 294 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-sidekiq.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Abdelkader Boudih 2 | 3 | capistrano-sidekiq is an Open Source project licensed under the terms of 4 | the LGPLv3 license. Please see 5 | for license text. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Capistrano::Sidekiq 2 | 3 | [![Gem Version](https://badge.fury.io/rb/capistrano-sidekiq.svg)](http://badge.fury.io/rb/capistrano-sidekiq) 4 | 5 | Sidekiq integration for Capistrano - providing systemd service management and deployment coordination. 6 | 7 | ## Installation 8 | 9 | Add to your Gemfile: 10 | 11 | ```ruby 12 | gem 'capistrano-sidekiq', group: :development 13 | ``` 14 | 15 | Then execute: 16 | 17 | ```bash 18 | $ bundle install 19 | ``` 20 | 21 | ## Setup 22 | 23 | Add to your Capfile: 24 | 25 | ```ruby 26 | # Capfile 27 | require 'capistrano/sidekiq' 28 | install_plugin Capistrano::Sidekiq # Default sidekiq tasks 29 | install_plugin Capistrano::Sidekiq::Systemd # Systemd integration 30 | ``` 31 | 32 | ## Configuration Options 33 | 34 | ### Basic Settings 35 | 36 | ```ruby 37 | # config/deploy.rb 38 | set :sidekiq_roles, :worker # Default role for Sidekiq processes 39 | set :sidekiq_default_hooks, true # Enable default deployment hooks 40 | set :sidekiq_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage))) # Environment for Sidekiq processes 41 | 42 | # Single config file 43 | set :sidekiq_config_files, ['sidekiq.yml'] 44 | 45 | # Multiple config files for different Sidekiq processes 46 | set :sidekiq_config_files, ['sidekiq.yml', 'sidekiq-high-priority.yml'] 47 | ``` 48 | 49 | ### Advanced Configuration 50 | 51 | ```ruby 52 | # Systemd service settings 53 | set :service_unit_user, :system # Run as system service (:system or :user) 54 | set :systemctl_user, true # Run systemctl in user mode 55 | set :sidekiq_service_unit_name, "custom_sidekiq_#{fetch(:stage)}" # Custom service name 56 | 57 | # Environment configuration 58 | set :sidekiq_service_unit_env_files, ['/etc/environment'] # Environment files 59 | set :sidekiq_service_unit_env_vars, [ # Environment variables 60 | 'RAILS_ENV=production', 61 | 'MALLOC_ARENA_MAX=2' 62 | ] 63 | 64 | # Logging configuration 65 | set :sidekiq_log, -> { File.join(shared_path, 'log', 'sidekiq.log') } 66 | set :sidekiq_error_log, -> { File.join(shared_path, 'log', 'sidekiq.error.log') } 67 | ``` 68 | 69 | ### Per-Server Configuration 70 | 71 | You can configure Sidekiq differently for specific servers: 72 | 73 | ```ruby 74 | # config/deploy/production.rb 75 | server 'worker1.example.com', 76 | roles: [:worker], 77 | sidekiq_config_files: ['sidekiq_1.yml'], 78 | sidekiq_user: 'custom_user' 79 | 80 | server 'worker2.example.com', 81 | roles: [:worker], 82 | sidekiq_config_files: ['sidekiq_2.yml'] 83 | ``` 84 | 85 | ## Available Tasks 86 | 87 | ```bash 88 | # View all available tasks 89 | cap -T sidekiq 90 | 91 | # Common commands 92 | cap sidekiq:start # Start Sidekiq 93 | cap sidekiq:stop # Stop Sidekiq (graceful shutdown) 94 | cap sidekiq:restart # Restart Sidekiq 95 | cap sidekiq:quiet # Quiet Sidekiq (stop processing new jobs) 96 | cap sidekiq:install # Install Sidekiq systemd service 97 | cap sidekiq:uninstall # Remove Sidekiq systemd service 98 | cap sidekiq:enable # Enable Sidekiq systemd service 99 | cap sidekiq:disable # Disable Sidekiq systemd service 100 | ``` 101 | 102 | ## Working with Systemd Logs 103 | 104 | View Sidekiq service logs using journalctl: 105 | 106 | ```bash 107 | # View last 100 lines of logs 108 | journalctl -u sidekiq_myapp_production -n 100 109 | 110 | # Follow logs in real-time 111 | journalctl -u sidekiq_myapp_production -f 112 | ``` 113 | 114 | ## Log File Configuration 115 | 116 | ### Modern Systemd (v240+, e.g., Ubuntu 20.04+) 117 | 118 | Log files are configured automatically using the `append:` functionality in the systemd service file. 119 | 120 | ### Legacy Systemd Systems 121 | 122 | For systems with older Systemd versions where `append:` is not supported: 123 | 124 | 1. Sidekiq messages are sent to syslog by default 125 | 2. Configure system logger to filter Sidekiq messages 126 | 127 | ## Example Application 128 | 129 | A complete example application demonstrating the usage of this gem is available at: 130 | https://github.com/seuros/capistrano-example-app 131 | 132 | ## Contributing 133 | 134 | 1. Fork the repository 135 | 2. Create your feature branch (`git checkout -b my-new-feature`) 136 | 3. Commit your changes (`git commit -am 'Add some feature'`) 137 | 4. Push to the branch (`git push origin my-new-feature`) 138 | 5. Create new Pull Request 139 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /SYSTEMD.md: -------------------------------------------------------------------------------- 1 | # Understanding Systemd Lingering in Capistrano Sidekiq 2 | 3 | ## What is Lingering? 4 | 5 | Lingering is a systemd feature that allows user services to run without an active user session. When lingering is enabled for a user: 6 | 7 | - Their user services can start at boot 8 | - Their user services continue running after they log out 9 | - Their user services can be managed independently of user sessions 10 | 11 | ## Why is Lingering Important for Sidekiq? 12 | 13 | When running Sidekiq as a user service (`:service_unit_user = :user`), lingering becomes important because: 14 | 15 | 1. Sidekiq needs to run continuously, even when no user is logged in 16 | 2. Sidekiq should start automatically after server reboots 17 | 3. Deployments should work regardless of active user sessions 18 | 19 | ## Configuration in Capistrano Sidekiq 20 | 21 | ```ruby 22 | set :sidekiq_lingering_user, -> { fetch(:lingering_user, fetch(:user)) } #lingering_user is optional, if the deploy user is the same 23 | set :service_unit_user, :user #set to :user to enable lingering 24 | ``` 25 | 26 | The plugin automatically enables lingering during the `sidekiq:enable` task when: 27 | - User-mode systemd is being used (`systemctl_user` is true) 28 | - A lingering user is specified 29 | 30 | ## How Lingering is Managed 31 | 32 | ### Enabling Lingering 33 | 34 | ```ruby 35 | # This happens automatically during sidekiq:enable if conditions are met 36 | execute :loginctl, "enable-linger", fetch(:sidekiq_lingering_user) 37 | ``` 38 | 39 | ### Checking Lingering Status 40 | 41 | You can manually check if lingering is enabled for a user: 42 | 43 | ```bash 44 | # Check lingering status 45 | loginctl show-user USERNAME | grep Linger 46 | 47 | # List all users with lingering enabled 48 | ls /var/lib/systemd/linger/ 49 | ``` 50 | 51 | ## Common Scenarios and Solutions 52 | 53 | ### Scenario 1: Running as Deploy User 54 | ```ruby 55 | # config/deploy.rb 56 | set :user, 'deploy' 57 | set :service_unit_user, :user 58 | # Lingering will be enabled for 'deploy' user 59 | ``` 60 | 61 | ### Scenario 2: Custom Lingering User 62 | ```ruby 63 | # config/deploy.rb 64 | set :user, 'deploy' 65 | set :lingering_user, 'sidekiq' 66 | set :service_unit_user, :user 67 | # Lingering will be enabled for 'sidekiq' user 68 | ``` 69 | 70 | ### Scenario 3: System Service (No Lingering Needed) 71 | ```ruby 72 | # config/deploy.rb 73 | set :service_unit_user, :system 74 | # Lingering is not relevant for system services 75 | ``` 76 | 77 | ## Troubleshooting 78 | 79 | 1. **Service Stops After Deployment** 80 | - Check if lingering is enabled: `loginctl show-user USERNAME | grep Linger` 81 | - Verify systemd user mode is correctly configured 82 | - Ensure the lingering user has appropriate permissions 83 | 84 | 2. **Service Doesn't Start on Boot** 85 | - Confirm lingering is enabled 86 | - Check systemd user service is enabled: `systemctl --user is-enabled sidekiq` 87 | - Verify service configuration in `~/.config/systemd/user/` 88 | 89 | 3. **Permission Issues** 90 | - Ensure the lingering user has access to required directories 91 | - Check if the user can write to log files and working directory 92 | - Verify systemd user instance is properly initialized 93 | 94 | ## Best Practices 95 | 96 | 1. **User Selection** 97 | - Use a dedicated service user for running Sidekiq 98 | - Ensure the user has minimal required permissions 99 | - Consider security implications of lingering enabled 100 | 101 | 2. **Configuration** 102 | - Always explicitly set `:service_unit_user` 103 | - Document lingering configuration in your deployment setup 104 | - Use consistent users across related services 105 | 106 | 3. **Monitoring** 107 | - Regularly check lingering status 108 | - Monitor service status after system reboots 109 | - Set up alerts for unexpected service stops 110 | 111 | ## System Requirements 112 | 113 | - Systemd version supporting user lingering (systemd >= 206) 114 | - Proper system permissions to enable lingering 115 | - Sufficient user permissions for service directories 116 | -------------------------------------------------------------------------------- /capistrano-sidekiq.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'lib/capistrano/sidekiq/version' 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = 'capistrano-sidekiq' 7 | spec.version = Capistrano::SidekiqVERSION 8 | spec.authors = ['Abdelkader Boudih'] 9 | spec.email = ['terminale@gmail.com'] 10 | spec.description = 'Sidekiq integration for Capistrano' 11 | spec.summary = 'Sidekiq integration for Capistrano' 12 | spec.homepage = 'https://github.com/seuros/capistrano-sidekiq' 13 | spec.license = 'LGPL-3.0' 14 | 15 | spec.required_ruby_version = '>= 2.5.0' 16 | 17 | spec.files = Dir.glob('lib/**/*') + %w[README.md CHANGELOG.md LICENSE.txt] 18 | spec.require_paths = ['lib'] 19 | 20 | spec.add_dependency 'capistrano', '>= 3.9.0' 21 | spec.add_dependency 'capistrano-bundler' 22 | spec.add_dependency 'sidekiq', '>= 6.0.6' 23 | spec.post_install_message = ' 24 | Version 3.0.0 is a major release. Please see README.md, breaking changes are listed in CHANGELOG.md 25 | ' 26 | end 27 | -------------------------------------------------------------------------------- /lib/capistrano-sidekiq.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seuros/capistrano-sidekiq/a3b9d9a811b40a22eb9fa61f05f522bb65a09a74/lib/capistrano-sidekiq.rb -------------------------------------------------------------------------------- /lib/capistrano/sidekiq.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'capistrano/bundler' 4 | require 'capistrano/plugin' 5 | 6 | module Capistrano 7 | module SidekiqCommon 8 | def compiled_template(config_file = "sidekiq.yml") 9 | @config_file = config_file 10 | local_template_directory = fetch(:sidekiq_service_templates_path) 11 | search_paths = [ 12 | File.join(local_template_directory, 'sidekiq.service.capistrano.erb'), 13 | File.expand_path( 14 | File.join(*%w[.. templates sidekiq.service.capistrano.erb]), 15 | __FILE__ 16 | ) 17 | ] 18 | template_path = search_paths.detect { |path| File.file?(path) } 19 | template = File.read(template_path) 20 | ERB.new(template, trim_mode: '-').result(binding) 21 | end 22 | 23 | def expanded_bundle_path 24 | backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip 25 | end 26 | 27 | def sidekiq_config 28 | "--config config/#{@config_file}" if @config_file != "sidekiq.yml" 29 | end 30 | 31 | def switch_user(role, &block) 32 | su_user = sidekiq_user(role) 33 | if su_user == role.user 34 | yield 35 | else 36 | as su_user, &block 37 | end 38 | end 39 | 40 | def sidekiq_user(role = nil) 41 | if role.nil? 42 | fetch(:sidekiq_user) 43 | else 44 | properties = role.properties 45 | properties.fetch(:sidekiq_user) || # local property for sidekiq only 46 | fetch(:sidekiq_user) || 47 | properties.fetch(:run_as) || # global property across multiple capistrano gems 48 | role.user 49 | end 50 | end 51 | end 52 | class Sidekiq < Capistrano::Plugin 53 | def define_tasks 54 | eval_rakefile File.expand_path('tasks/sidekiq.rake', __dir__) 55 | end 56 | 57 | def set_defaults 58 | set_if_empty :sidekiq_default_hooks, true 59 | 60 | set_if_empty :sidekiq_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:rake_env, fetch(:stage)))) } 61 | set_if_empty :sidekiq_roles, fetch(:sidekiq_role, :worker) 62 | set_if_empty :sidekiq_configs, %w[sidekiq] # sidekiq.yml 63 | 64 | set_if_empty :sidekiq_log, -> { File.join(shared_path, 'log', 'sidekiq.log') } 65 | set_if_empty :sidekiq_error_log, -> { File.join(shared_path, 'log', 'sidekiq.log') } 66 | 67 | set_if_empty :sidekiq_config_files, ['sidekiq.yml'] 68 | 69 | # Rbenv, Chruby, and RVM integration 70 | append :rbenv_map_bins, 'sidekiq', 'sidekiqctl' 71 | append :rvm_map_bins, 'sidekiq', 'sidekiqctl' 72 | append :chruby_map_bins, 'sidekiq', 'sidekiqctl' 73 | # Bundler integration 74 | append :bundle_bins, 'sidekiq', 'sidekiqctl' 75 | end 76 | end 77 | end 78 | 79 | require_relative 'sidekiq/systemd' 80 | -------------------------------------------------------------------------------- /lib/capistrano/sidekiq/systemd.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Capistrano 4 | class Sidekiq::Systemd < Capistrano::Plugin 5 | include SidekiqCommon 6 | def define_tasks 7 | eval_rakefile File.expand_path('../tasks/systemd.rake', __dir__) 8 | end 9 | def set_defaults 10 | set_if_empty :systemctl_bin, '/bin/systemctl' 11 | set_if_empty :service_unit_user, :user 12 | set_if_empty :systemctl_user, fetch(:service_unit_user, :user) == :user 13 | 14 | set_if_empty :sidekiq_service_unit_name, -> { "#{fetch(:application)}_sidekiq_#{fetch(:stage)}" } 15 | set_if_empty :sidekiq_lingering_user, -> { fetch(:lingering_user, fetch(:user)) } 16 | 17 | ## Sidekiq could have a stripped down or more complex version of the environment variables 18 | set_if_empty :sidekiq_service_unit_env_files, -> { fetch(:service_unit_env_files, []) } 19 | set_if_empty :sidekiq_service_unit_env_vars, -> { fetch(:service_unit_env_vars, []) } 20 | 21 | set_if_empty :sidekiq_service_templates_path, fetch(:service_templates_path, 'config/deploy/templates') 22 | end 23 | 24 | def systemd_command(*args) 25 | command = [fetch(:systemctl_bin)] 26 | 27 | unless fetch(:service_unit_user) == :system 28 | command << "--user" 29 | end 30 | 31 | command + args 32 | end 33 | 34 | def sudo_if_needed(*command) 35 | if fetch(:service_unit_user) == :system 36 | backend.sudo command.map(&:to_s).join(" ") 37 | else 38 | backend.execute(*command) 39 | end 40 | end 41 | 42 | def execute_systemd(*args) 43 | sudo_if_needed(*systemd_command(*args)) 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/capistrano/sidekiq/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Capistrano 4 | SidekiqVERSION = '3.0.0' 5 | end 6 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/sidekiq.rake: -------------------------------------------------------------------------------- 1 | namespace :deploy do 2 | before :starting, :check_sidekiq_hooks do 3 | invoke 'sidekiq:add_default_hooks' if fetch(:sidekiq_default_hooks) 4 | end 5 | end 6 | 7 | namespace :sidekiq do 8 | task :add_default_hooks do 9 | after 'deploy:starting', 'sidekiq:quiet' if Rake::Task.task_defined?('sidekiq:quiet') 10 | after 'deploy:updated', 'sidekiq:stop' 11 | after 'deploy:reverted', 'sidekiq:stop' 12 | after 'deploy:published', 'sidekiq:start' 13 | after 'deploy:failed', 'sidekiq:restart' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/systemd.rake: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # frozen_string_literal: true 3 | 4 | git_plugin = self 5 | 6 | namespace :sidekiq do 7 | standard_actions = { 8 | start: 'Start Sidekiq', 9 | stop: 'Stop Sidekiq (graceful shutdown within timeout, put unfinished tasks back to Redis)', 10 | status: 'Get Sidekiq Status', 11 | restart: 'Restart Sidekiq' 12 | } 13 | standard_actions.each do |command, description| 14 | desc description 15 | task command do 16 | on roles fetch(:sidekiq_roles) do |role| 17 | git_plugin.switch_user(role) do 18 | git_plugin.config_files(role).each do |config_file| 19 | git_plugin.execute_systemd(command, git_plugin.sidekiq_service_file_name(config_file)) 20 | end 21 | end 22 | end 23 | end 24 | end 25 | 26 | desc 'Quiet Sidekiq (stop fetching new tasks from Redis)' 27 | task :quiet do 28 | on roles fetch(:sidekiq_roles) do |role| 29 | git_plugin.switch_user(role) do 30 | git_plugin.quiet_sidekiq(role) 31 | end 32 | end 33 | end 34 | 35 | desc 'Install Sidekiq systemd service' 36 | task :install do 37 | on roles fetch(:sidekiq_roles) do |role| 38 | git_plugin.switch_user(role) do 39 | git_plugin.create_systemd_template(role) 40 | end 41 | end 42 | invoke 'sidekiq:enable' 43 | end 44 | 45 | desc 'Uninstall Sidekiq systemd service' 46 | task :uninstall do 47 | invoke 'sidekiq:disable' 48 | on roles fetch(:sidekiq_roles) do |role| 49 | git_plugin.switch_user(role) do 50 | git_plugin.rm_systemd_service(role) 51 | end 52 | end 53 | end 54 | 55 | desc 'Enable Sidekiq systemd service' 56 | task :enable do 57 | on roles(fetch(:sidekiq_roles)) do |role| 58 | git_plugin.config_files(role).each do |config_file| 59 | git_plugin.execute_systemd("enable", git_plugin.sidekiq_service_file_name(config_file)) 60 | end 61 | 62 | if fetch(:systemctl_user) && fetch(:sidekiq_lingering_user) 63 | execute :loginctl, "enable-linger", fetch(:sidekiq_lingering_user) 64 | end 65 | end 66 | end 67 | 68 | desc 'Disable Sidekiq systemd service' 69 | task :disable do 70 | on roles(fetch(:sidekiq_roles)) do |role| 71 | git_plugin.config_files(role).each do |config_file| 72 | git_plugin.execute_systemd("disable", git_plugin.sidekiq_service_file_name(config_file)) 73 | end 74 | end 75 | end 76 | 77 | def fetch_systemd_unit_path 78 | if fetch(:sidekiq_systemctl_user) == :system 79 | "/etc/systemd/system/" 80 | else 81 | home_dir = backend.capture :pwd 82 | File.join(home_dir, ".config", "systemd", "user") 83 | end 84 | end 85 | 86 | def create_systemd_template(role) 87 | systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path) 88 | backend.execute :mkdir, '-p', systemd_path if fetch(:systemctl_user) 89 | 90 | config_files(role).each do |config_file| 91 | ctemplate = compiled_template(config_file) 92 | temp_file_name = File.join('/tmp', "sidekiq.#{config_file}.service") 93 | systemd_file_name = File.join(systemd_path, sidekiq_service_file_name(config_file)) 94 | backend.upload!(StringIO.new(ctemplate), temp_file_name) 95 | if fetch(:systemctl_user) 96 | warn "Moving #{temp_file_name} to #{systemd_file_name}" 97 | backend.execute :mv, temp_file_name, systemd_file_name 98 | else 99 | warn "Installing #{systemd_file_name} as root" 100 | backend.execute :sudo, :mv, temp_file_name, systemd_file_name 101 | end 102 | end 103 | end 104 | 105 | def rm_systemd_service(role) 106 | systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path) 107 | 108 | config_files(role).each do |config_file| 109 | systemd_file_name = File.join(systemd_path, sidekiq_service_file_name(config_file)) 110 | if fetch(:systemctl_user) 111 | warn "Deleting #{systemd_file_name}" 112 | backend.execute :rm, "-f", systemd_file_name 113 | else 114 | warn "Deleting #{systemd_file_name} as root" 115 | backend.execute :sudo, :rm, "-f", systemd_file_name 116 | end 117 | end 118 | end 119 | 120 | def quiet_sidekiq(role) 121 | config_files(role).each do |config_file| 122 | sidekiq_service = sidekiq_service_unit_name(config_file) 123 | warn "Quieting #{sidekiq_service}" 124 | execute_systemd("kill -s TSTP", sidekiq_service) 125 | end 126 | end 127 | 128 | def sidekiq_service_unit_name(config_file) 129 | if config_file != "sidekiq.yml" 130 | fetch(:sidekiq_service_unit_name) + "." + config_file.split(".")[0..-2].join(".") 131 | else 132 | fetch(:sidekiq_service_unit_name) 133 | end 134 | end 135 | 136 | def sidekiq_service_file_name(config_file) 137 | ## Remove the extension 138 | config_file = config_file.split('.')[0..-1].join('.') 139 | 140 | "#{sidekiq_service_unit_name(config_file)}.service" 141 | end 142 | 143 | def config_files(role) 144 | role.properties.fetch(:sidekiq_config_files) || 145 | fetch(:sidekiq_config_files) 146 | end 147 | end 148 | -------------------------------------------------------------------------------- /lib/capistrano/templates/sidekiq.service.capistrano.erb: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/mperham/sidekiq/blob/master/examples/systemd/sidekiq.service 2 | # 3 | # This file tells systemd how to run Sidekiq as a 24/7 long-running daemon. 4 | 5 | # Then run: 6 | # - systemctl enable <%= sidekiq_service_unit_name(@config_file) %> 7 | # - systemctl {start,stop,restart} <%= sidekiq_service_unit_name(@config_file) %> 8 | # 9 | # Use `journalctl -u <%= sidekiq_service_unit_name(@config_file) %> -rn 100` to view the last 100 lines of log output. 10 | # 11 | [Unit] 12 | Description=Sidekiq for <%= "#{fetch(:application)} (#{fetch(:stage)})" %> 13 | # start us only once the network and logging subsystems are available, 14 | # consider adding redis-server.service if Redis is local and systemd-managed. 15 | After=syslog.target network.target 16 | 17 | [Service] 18 | Type=notify 19 | # If your Sidekiq process locks up, systemd's watchdog will restart it within seconds. 20 | WatchdogSec=10 21 | <%="User=#{sidekiq_user}" if fetch(:sidekiq_systemctl_user) == :system %> 22 | WorkingDirectory=<%= current_path %> 23 | ExecStart=<%= expanded_bundle_path %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> 24 | 25 | # Use `systemctl kill -s TSTP <% sidekiq_service_unit_name(@config_file) %>` to quiet the Sidekiq process 26 | UMask=0002 27 | 28 | <%- Array(fetch(:sidekiq_service_unit_env_files)).each do |file| %> 29 | <%="EnvironmentFile=#{file}" %> 30 | <% end -%> 31 | <% Array(fetch(:sidekiq_service_unit_env_vars)).each do |environment_variable| %> 32 | <%="Environment=\"#{environment_variable}\"" %> 33 | <% end -%> 34 | 35 | # if we crash, restart 36 | RestartSec=1 37 | Restart=on-failure 38 | 39 | <%="StandardOutput=append:#{fetch(:sidekiq_log)}" if fetch(:sidekiq_log) -%> 40 | 41 | <%="StandardError=append:#{fetch(:sidekiq_error_log)}" if fetch(:sidekiq_error_log) -%> 42 | 43 | SyslogIdentifier=<%= sidekiq_service_unit_name(@config_file) %> 44 | [Install] 45 | WantedBy=<%=(fetch(:sidekiq_systemctl_user) == :system) ? "multi-user.target" : "default.target"%> 46 | --------------------------------------------------------------------------------