質問編集履歴

12

想定される結果追加。

2018/06/14 09:39

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -234,6 +234,28 @@
234
234
 
235
235
 
236
236
 
237
+ ## 想定される結果
238
+
239
+ 下記のように、storage/logs/laravel.logに追加される。
240
+
241
+ ```
242
+
243
+ [2018-06-14 14:30:02] staging.INFO: start scedule
244
+
245
+ [2018-06-14 14:30:02] staging.INFO: handle start
246
+
247
+ [2018-06-14 14:30:02] staging.INFO: end scedule
248
+
249
+ [2018-06-14 14:31:01] staging.INFO: start scedule
250
+
251
+ [2018-06-14 14:31:01] staging.INFO: handle start
252
+
253
+ [2018-06-14 14:31:01] staging.INFO: end scedule
254
+
255
+ ```
256
+
257
+
258
+
237
259
  ## 現象
238
260
 
239
261
 

11

laravelのバージョン追加

2018/06/14 09:39

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -292,6 +292,12 @@
292
292
 
293
293
  ## わかっている事
294
294
 
295
+ ### laravelのバージョン
296
+
297
+ Laravel Framework 5.5.40
298
+
299
+
300
+
295
301
  ### 環境
296
302
 
297
303
  OSは、「CentOS release 6.9」です。

10

試した事追加。

2018/06/14 09:27

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -316,6 +316,8 @@
316
316
 
317
317
  ## 試した事
318
318
 
319
+ ### commandで意図的にエラーを起こす
320
+
319
321
  もしかして、Commandにエラーがあってもエラーをログに吐かないのかと思い、意図的に構文エラーをして見ました。
320
322
 
321
323
 
@@ -349,3 +351,9 @@
349
351
  storageに書き出す部分のみの問題な気がします。
350
352
 
351
353
  何故、scheduleのbeforeとafterは良くて、Commandが書き出せないのかわかりませんが…
354
+
355
+
356
+
357
+ ### storageディレクトリ以下のパーミッションを777にする。
358
+
359
+ laravel.logのパーミッションが元々「-rw-r--r--」で、projectユーザー(作業ユーザー)しかさわれない状態だったので、laravel.logのパーミッションを777にしてみましたが、logsに書き込まれませんでした。

9

試した事に追記

2018/06/14 06:41

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -346,4 +346,6 @@
346
346
 
347
347
 
348
348
 
349
- storageに書き出す部分のみの問題な気がします
349
+ storageに書き出す部分のみの問題な気がします
350
+
351
+ 何故、scheduleのbeforeとafterは良くて、Commandが書き出せないのかわかりませんが…

8

試した事追加

2018/06/14 06:14

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -286,6 +286,10 @@
286
286
 
287
287
  ```
288
288
 
289
+
290
+
291
+
292
+
289
293
  ## わかっている事
290
294
 
291
295
  ### 環境
@@ -307,3 +311,39 @@
307
311
  projectユーザーのホームディレクトリ配下に展開しています。
308
312
 
309
313
  projectユーザーのホームディレクトリは、/home/project/です。
314
+
315
+
316
+
317
+ ## 試した事
318
+
319
+ もしかして、Commandにエラーがあってもエラーをログに吐かないのかと思い、意図的に構文エラーをして見ました。
320
+
321
+
322
+
323
+ ```
324
+
325
+ public function handle()
326
+
327
+ {
328
+
329
+ $monolog = \Log::getMonolog()
330
+
331
+ $monolog->info('handle start');
332
+
333
+ }
334
+
335
+ ```
336
+
337
+
338
+
339
+ その結果、下記のエラーが吐き出されるので、Command自体は実行されています。
340
+
341
+ ``` sh
342
+
343
+ staging.ERROR: Parse error: syntax error, unexpected '$monolog' (T_VARIABLE) {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '$monolog' (T_VARIABLE) at /home/project/app/Console/Commands/Test.php:41)
344
+
345
+ ```
346
+
347
+
348
+
349
+ storageに書き出す部分のみの問題な気がします、

7

Kernelのcommands変数に、classを定義する件を検証しましたが変わりませんでしたので追記。

2018/06/14 06:12

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  protected $commands = [
58
58
 
59
- //
59
+ \App\Console\Commands\Test::class,
60
60
 
61
61
  ];
62
62
 

6

タイトルを本文に寄せて修正

2018/06/14 05:43

投稿

pip
pip

スコア19

test CHANGED
@@ -1 +1 @@
1
- Laravelのスケジュールが実行されない
1
+ Laravelのスケジュールに設定したCommandが実行されない
test CHANGED
File without changes

5

状況をわかりやすくするために、ログ調整

2018/06/14 05:34

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -84,7 +84,23 @@
84
84
 
85
85
  ->cron('* * * * * *')
86
86
 
87
+ ->before(function(){
88
+
89
+ $monolog = \Log::getMonolog();
90
+
91
+ $monolog->info('start scedule');
92
+
93
+ })
94
+
87
- ->timezone('Asia/Tokyo');
95
+ ->timezone('Asia/Tokyo')
96
+
97
+ ->after(function(){
98
+
99
+ $monolog = \Log::getMonolog();
100
+
101
+ $monolog->info('end scedule');
102
+
103
+ });
88
104
 
89
105
  }
90
106
 
@@ -230,13 +246,13 @@
230
246
 
231
247
  ```
232
248
 
249
+ [2018-06-14 14:30:02] staging.INFO: start scedule
250
+
251
+ [2018-06-14 14:30:02] staging.INFO: end scedule
252
+
253
+ [2018-06-14 14:31:01] staging.INFO: start scedule
254
+
233
- [2018-06-14 12:26:01] staging.INFO: schedule start
255
+ [2018-06-14 14:31:01] staging.INFO: end scedule
234
-
235
- [2018-06-14 12:27:02] staging.INFO: schedule start
236
-
237
- [2018-06-14 12:28:01] staging.INFO: schedule start
238
-
239
- [2018-06-14 12:29:01] staging.INFO: schedule start
240
256
 
241
257
  ```
242
258
 

4

ソースの内容を詳細に記載。

2018/06/14 05:32

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -20,46 +20,200 @@
20
20
 
21
21
  ### Laravel側のスケジュール
22
22
 
23
+
24
+
25
+ Console/Kernel.php
26
+
23
27
  ``` php
24
28
 
29
+ <?php
30
+
31
+
32
+
33
+ namespace App\Console;
34
+
35
+
36
+
37
+ use Illuminate\Console\Scheduling\Schedule;
38
+
39
+ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
40
+
41
+
42
+
43
+ class Kernel extends ConsoleKernel
44
+
45
+ {
46
+
47
+ /**
48
+
49
+ * The Artisan commands provided by your application.
50
+
51
+ *
52
+
53
+ * @var array
54
+
55
+ */
56
+
57
+ protected $commands = [
58
+
59
+ //
60
+
61
+ ];
62
+
63
+
64
+
65
+ /**
66
+
67
+ * Define the application's command schedule.
68
+
69
+ *
70
+
71
+ * @param \Illuminate\Console\Scheduling\Schedule $schedule
72
+
73
+ * @return void
74
+
75
+ */
76
+
25
- protected function schedule(Schedule $schedule)
77
+ protected function schedule(Schedule $schedule)
26
-
78
+
27
- {
79
+ {
80
+
81
+
82
+
28
-
83
+ $schedule->command('command:test')
84
+
29
-
85
+ ->cron('* * * * * *')
86
+
87
+ ->timezone('Asia/Tokyo');
88
+
89
+ }
90
+
91
+
92
+
93
+ /**
94
+
95
+ * Register the commands for the application.
96
+
97
+ *
98
+
99
+ * @return void
100
+
101
+ */
102
+
103
+ protected function commands()
104
+
105
+ {
106
+
107
+ $this->load(__DIR__.'/Commands');
108
+
109
+
110
+
111
+ require base_path('routes/console.php');
112
+
113
+ }
114
+
115
+ }
116
+
117
+
118
+
119
+ ```
120
+
121
+
122
+
123
+ command:testは下記を実行します。
124
+
125
+ Console/Commands/Test.php
126
+
127
+ ```
128
+
129
+ <?php
130
+
131
+
132
+
133
+ namespace App\Console\Commands;
134
+
135
+
136
+
137
+ use Illuminate\Console\Command;
138
+
139
+
140
+
141
+ class Test extends Command
142
+
143
+ {
144
+
145
+ /**
146
+
147
+ * The name and signature of the console command.
148
+
149
+ *
150
+
151
+ * @var string
152
+
153
+ */
154
+
155
+ protected $signature = 'command:test';
156
+
157
+
158
+
159
+ /**
160
+
161
+ * The console command description.
162
+
163
+ *
164
+
165
+ * @var string
166
+
167
+ */
168
+
169
+ protected $description = 'Command Test';
170
+
171
+
172
+
173
+ /**
174
+
175
+ * Create a new command instance.
176
+
177
+ *
178
+
179
+ * @return void
180
+
181
+ */
182
+
183
+ public function __construct()
184
+
185
+ {
186
+
187
+ parent::__construct();
188
+
189
+ }
190
+
191
+
192
+
193
+ /**
194
+
195
+ * Execute the console command.
196
+
197
+ *
198
+
199
+ * @return mixed
200
+
201
+ */
202
+
203
+ public function handle()
204
+
205
+ {
30
206
 
31
207
  $monolog = \Log::getMonolog();
32
208
 
33
- $monolog->info('schedule start');
34
-
35
-
36
-
37
- $schedule->command('command:test')
38
-
39
- ->cron('* * * * * *')
40
-
41
- ->timezone('Asia/Tokyo');
42
-
43
- }
44
-
45
- ```
46
-
47
-
48
-
49
- command:testは下記を実行します。
50
-
51
- ```
52
-
53
- public function handle()
54
-
55
- {
56
-
57
- $monolog = \Log::getMonolog();
58
-
59
209
  $monolog->info('handle start');
60
210
 
61
211
  }
62
212
 
213
+ }
214
+
215
+
216
+
63
217
  ```
64
218
 
65
219
 

3

ログ情報を追加

2018/06/14 05:24

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -102,6 +102,20 @@
102
102
 
103
103
 
104
104
 
105
+ ### cronで実行したタスクのログ(dumplog.txt)
106
+
107
+ 毎分出力する設定にしていますので、指定したスケジュールで、実行自体はしているのはわかります。
108
+
109
+ ```
110
+
111
+ Running scheduled command: '/opt/lampp/bin/php-7.1.14' 'artisan' command:test > '/dev/null' 2>&1
112
+
113
+ Running scheduled command: '/opt/lampp/bin/php-7.1.14' 'artisan' command:test > '/dev/null' 2>&1
114
+
115
+ Running scheduled command: '/opt/lampp/bin/php-7.1.14' 'artisan' command:test > '/dev/null' 2>&1
116
+
117
+ ```
118
+
105
119
  ## わかっている事
106
120
 
107
121
  ### 環境

2

情報を追加しました。

2018/06/14 04:09

投稿

pip
pip

スコア19

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ```cron.d
14
14
 
15
- * * * * * root /opt/lampp/bin/php /home/project/artisan schedule:run >> dump_cronlog.txt
15
+ * * * * * root /opt/lampp/bin/php /home/project/artisan schedule:run >> /dumplog.txt
16
16
 
17
17
  ```
18
18
 
@@ -72,6 +72,8 @@
72
72
 
73
73
 
74
74
 
75
+ ### laravelログ
76
+
75
77
  ```
76
78
 
77
79
  [2018-06-14 12:26:01] staging.INFO: schedule start
@@ -85,6 +87,18 @@
85
87
  ```
86
88
 
87
89
 
90
+
91
+ ### cronログ
92
+
93
+ 取得時間に際がありますが、cronで、スケジュールの実行自体はされています。
94
+
95
+ ```
96
+
97
+ Jun 14 12:59:01 ik1-325-22848 CROND[6628]: (root) CMD (/opt/lampp/bin/php /home/project/artisan schedule:run >> /dumplog.txt)
98
+
99
+ Jun 14 13:00:01 ik1-325-22848 CROND[6649]: (root) CMD (/opt/lampp/bin/php /home/project/artisan schedule:run >> /dumplog.txt)
100
+
101
+ ```
88
102
 
89
103
 
90
104
 

1

問題はCronの設定ではなく、Laravelのタスクが実行されていない事なので内容自体を変更します。

2018/06/14 04:04

投稿

pip
pip

スコア19

test CHANGED
@@ -1 +1 @@
1
- cronが実行すると勝手に書き換わる現象が解決できない
1
+ Laravelのスケジュールが実行されない
test CHANGED
@@ -8,9 +8,11 @@
8
8
 
9
9
  ### cron.dで設定しているタスク
10
10
 
11
+ rootのcron.dに下記を設定しています。
12
+
11
13
  ```cron.d
12
14
 
13
- * * * * * root /opt/lampp/bin/php /home/project/artisan schedule:run >> /dev/null 2>&1
15
+ * * * * * root /opt/lampp/bin/php /home/project/artisan schedule:run >> dump_cronlog.txt
14
16
 
15
17
  ```
16
18
 
@@ -24,11 +26,19 @@
24
26
 
25
27
  {
26
28
 
29
+
30
+
31
+ $monolog = \Log::getMonolog();
32
+
33
+ $monolog->info('schedule start');
34
+
35
+
36
+
27
37
  $schedule->command('command:test')
28
38
 
29
- ->dailyAt('3:00')
39
+ ->cron('* * * * * *')
30
40
 
31
- ->timezone('Asia/Tokyo');
41
+ ->timezone('Asia/Tokyo');
32
42
 
33
43
  }
34
44
 
@@ -36,31 +46,41 @@
36
46
 
37
47
 
38
48
 
49
+ command:testは下記を実行します。
39
50
 
51
+ ```
40
52
 
41
- ## 現象
53
+ public function handle()
42
54
 
43
- 上記タスクに登録したコマンドを手動で入力すると次のように変わってしまいます。
55
+ {
44
56
 
57
+ $monolog = \Log::getMonolog();
45
58
 
59
+ $monolog->info('handle start');
46
60
 
47
- ```sh
61
+ }
48
-
49
- $ /opt/lampp/bin/php /home/project/artisan schedule:run
50
-
51
- Running scheduled command: '/opt/lampp/bin/php-7.1.14' 'artisan' command:test > '/dev/null' 2>&1
52
62
 
53
63
  ```
54
64
 
55
65
 
56
66
 
57
- 「Running scheduled command」に出力されるコマンドを入力すると実行できません。
67
+ ## 現象
58
68
 
59
- ``` sh
60
69
 
61
- $ /opt/lampp/bin/php-7.1.14 artisan command:test
62
70
 
71
+ 毎分指定しているスケジュールなのですが、指定したcommandが実行できていません。
72
+
73
+
74
+
75
+ ```
76
+
63
- Could not open input file: artisan
77
+ [2018-06-14 12:26:01] staging.INFO: schedule start
78
+
79
+ [2018-06-14 12:27:02] staging.INFO: schedule start
80
+
81
+ [2018-06-14 12:28:01] staging.INFO: schedule start
82
+
83
+ [2018-06-14 12:29:01] staging.INFO: schedule start
64
84
 
65
85
  ```
66
86
 
@@ -84,36 +104,6 @@
84
104
 
85
105
 
86
106
 
87
- ### commandの実行
88
-
89
- 下記のコマンド、
90
-
91
- ``` sh
92
-
93
- $ cd /home/project/
94
-
95
- $ php artisan command:test
96
-
97
- ```
98
-
99
-
100
-
101
- もしくは、
102
-
103
- ``` sh
104
-
105
- $ /opt/lampp/bin/php-7.1.14 /home/project/artisan command:test
106
-
107
- ```
108
-
109
-
110
-
111
- 上記で、想定した結果が出力される事は確認しました。
112
-
113
- cronで実行されるときに、'artisan'の部分が書き換わる事だけが問題です。
114
-
115
-
116
-
117
107
  ### Laravelのプロジェクトのディレクトリ
118
108
 
119
109
  projectユーザーのホームディレクトリ配下に展開しています。