When I ran a task in Capistrano3 by changing the stage environment, I fell into the symptom of the task being launched twice. Since the task is executed in duplicate, even if you set "two" AWS instances to be launched, "four" will occur, and the queries issued to MySQL will also be doubled, and the records to be INSERTED will be inserted in duplicates. The settings that had been temporarily written to the file were also overwritten by the subsequent tasks that were being started twice, and the deployment was already in a messy state. Now that I have solved it, I will leave a memorandum of what to do at that time.
The reason was that the default deployment environment was specified in the invoke settings.
When I was developing a deployment task in a test environment, I wrote the following settings in the capfile.
Rake::Task[:develop].invoke
invoke :develop
If you write this, the default deployment environment will be fixed to 'develop', so when you run the deployment command, you should specify the deployment environment (stage name) and
$ cap develop deploy:task_name
Where you do it like this,
$ cap deploy:task_name
It was a little easier to omit the deployment environment, but this had a negative impact when deploying other than the default deployment environment.
This time, the deployment went well in the test environment, so the next deployment was done in the production environment, and the deployment environment (stage name) was run with 'production'. Since the deployment content was exactly the same as the test environment, there was no difference in deployment task settings, and the role settings and SSH connection settings were the same, so 'config/deploy/production.rb' was copied and 'config/deploy/production.rb' was created. In this state, you can specify the deployment environment and execute the deployment as shown below.
$ cap production deploy:task_name
This will also start the deployment to the default deployment environment that is omitted. In fact,
$ cap develop production deploy:task_name
It is the same as specifying two environments and performing a deployment.
To get rid of this condition, simply remove the aforementioned invoke settings. In other words, when deployments occur for multiple environments, it can cause confusion, so it is better not to set up invoke.
No, I was hooked for a few hours until I solved it. I have to be careful in the future.