groovenauts / capistrano-systemd-multiservice

Capistrano Plugin to control services with systemd
MIT License
45 stars 17 forks source link

Removing already installed services #37

Open scarroll32 opened 1 year ago

scarroll32 commented 1 year ago

I installed a redis systemd service manually, and don't seem to be able to remove it via this gem.

❯ be cap production systemd:redis:disable
00:00 systemd:redis:disable
      01 sudo systemctl disable immersive_redis.service
      01 Removed /etc/systemd/system/multi-user.target.wants/immersive_redis.service.
    ✔ 01 deploy@192.168.50.2 0.211s
~/immersive/immersive main
❯ be cap production systemd:redis:remove
00:00 systemd:redis:disable
      01 sudo systemctl disable immersive_redis.service
    ✔ 01 deploy@192.168.50.2 0.258s
00:00 systemd:redis:remove
      01 sudo rm -f -- /etc/systemd/system/immersive_redis.service
    ✔ 01 deploy@192.168.50.2 0.011s
00:00 systemd:redis:daemon-reload
      01 sudo systemctl daemon-reload
    ✔ 01 deploy@192.168.50.2 0.208s
~/immersive/immersive main
❯ be cap production systemd:redis:setup
/Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/bundler/gems/capistrano-systemd-multiservice-9ade1d3607f7/lib/capistrano/systemd/multiservice/system_service.rb:80: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.
/Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/bundler/gems/capistrano-systemd-multiservice-9ade1d3607f7/lib/capistrano/systemd/multiservice/system_service.rb:80: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.
00:00 systemd:redis:setup
      Uploading /tmp/redis.service 100.0%
      01 sudo install -m 644 -o root -g root -D /tmp/redis.service /etc/systemd/system/immersive_redis.service
    ✔ 01 deploy@192.168.50.2 0.017s
      02 rm /tmp/redis.service
    ✔ 02 deploy@192.168.50.2 0.007s
00:00 systemd:redis:daemon-reload
      01 sudo systemctl daemon-reload
    ✔ 01 deploy@192.168.50.2 0.257s
00:00 systemd:redis:enable
      01 sudo systemctl enable immersive_redis.service
      01 Failed to enable unit: File /etc/systemd/system/redis.service already exists.
#<Thread:0x0000000104ec7318 /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@192.168.50.2: sudo exit status: 1 (SSHKit::Runner::ExecuteError)
sudo stdout: Failed to enable unit: File /etc/systemd/system/redis.service already exists.
sudo stderr: Nothing written

    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/command.rb:97:in `exit_status=': sudo exit status: 1 (SSHKit::Command::Failed)
sudo stdout: Failed to enable unit: File /etc/systemd/system/redis.service already exists.
sudo stderr: Nothing written

    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/netssh.rb:170:in `execute_command'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
    from <internal:kernel>:90:in `tap'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/abstract.rb:80:in `execute'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/bundler/gems/capistrano-systemd-multiservice-9ade1d3607f7/lib/capistrano/systemd/multiservice/system_service.rb:110:in `systemctl'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/bundler/gems/capistrano-systemd-multiservice-9ade1d3607f7/lib/capistrano/systemd/multiservice/system_service.rb:104:in `block (2 levels) in <class:SystemService>'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/bundler/gems/capistrano-systemd-multiservice-9ade1d3607f7/lib/capistrano/tasks/systemd/multiservice/system_service.rake:22:in `block (5 levels) in eval_rakefile'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/backends/abstract.rb:31:in `run'
    from /Users/sean/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/sshkit-1.21.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@192.168.50.2: sudo exit status: 1
sudo stdout: Failed to enable unit: File /etc/systemd/system/redis.service already exists.
sudo stderr: Nothing written

Caused by:
SSHKit::Command::Failed: sudo exit status: 1
sudo stdout: Failed to enable unit: File /etc/systemd/system/redis.service already exists.
sudo stderr: Nothing written

Tasks: TOP => systemd:redis:enable
(See full trace by running task with --trace)
HLFH commented 1 year ago

@scarroll32 Have you set in your Capfile

require "capistrano/systemd/multiservice"
install_plugin Capistrano::Systemd::MultiService.new_service("redis")

Have you set config/systemd/redis.erb.service? In config/deploy.rb, have you set set :application, "immersive"? You can have a look at my fork as well: https://github.com/HLFH/capistrano-systemd-ng.