質問編集履歴

2

ファイル修正によるstatusの変更を追記しました

2019/10/11 07:21

投稿

begenner
begenner

スコア79

test CHANGED
File without changes
test CHANGED
@@ -295,3 +295,95 @@
295
295
  $ sudo systemctl start start-app
296
296
 
297
297
  ```
298
+
299
+
300
+
301
+
302
+
303
+ ### 追記3
304
+
305
+ ごにょごにょしてたらstatusに表示されるメッセージが変更されていたので追記します。
306
+
307
+ 依然としてどの処理でエラーが発生しているのか、動作の妨げになっているのかわかりません(m_ _m)
308
+
309
+ 参考: [[CentOS7] systemdにサービスを登録して、サーバ起動時に自動でサービスを立ち上げる | RE:ENGINES](https://re-engines.com/2018/07/23/centos7-systemd%E3%81%AB%E3%82%B5%E3%83%BC%E3%83%93%E3%82%B9%E3%82%92%E7%99%BB%E9%8C%B2%E3%81%97%E3%81%A6%E3%80%81%E3%82%B5%E3%83%BC%E3%83%90%E8%B5%B7%E5%8B%95%E6%99%82%E3%81%AB%E8%87%AA%E5%8B%95/)
310
+
311
+
312
+
313
+ ```bash
314
+
315
+ [Unit]
316
+
317
+ Description = start-app daemon
318
+
319
+
320
+
321
+ [Service]
322
+
323
+ User = myusername
324
+
325
+
326
+
327
+ # 環境変数パス
328
+
329
+ EnvironmentFile=/etc/systemd/env
330
+
331
+
332
+
333
+
334
+
335
+ ExecStart = /home/myusername/start.sh
336
+
337
+ Restart = always
338
+
339
+ Type = simple
340
+
341
+
342
+
343
+ [Install]
344
+
345
+ WantedBy = multi-user.target
346
+
347
+ ```
348
+
349
+
350
+
351
+ ```bash
352
+
353
+ # /etc/systemd/env
354
+
355
+ PATH=/home/myusername/.rbenv/shims:/home/myusername/.rbenv/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/myusername/.local/bin:/home/myusername/bin
356
+
357
+ ```
358
+
359
+
360
+
361
+ #### 追記、修正後の結果
362
+
363
+ ```bash
364
+
365
+ [myusername@ip-10-0-1-127 ~]$ sudo systemctl status start-app.service
366
+
367
+ # ● start-app.service - start-app daemon
368
+
369
+ # Loaded: loaded (/etc/systemd/system/start-app.service; enabled; vendor preset: disabled)
370
+
371
+ # Active: active (running) since 金 2019-10-11 07:01:56 UTC; 4s ago
372
+
373
+ # Main PID: 3842 (start.sh)
374
+
375
+ # CGroup: /system.slice/start-app.service
376
+
377
+ # ├─3842 /bin/sh /home/myusername/start.sh
378
+
379
+ # └─3843 /var/www/rails/myapp/vendor/bundle/ruby/2.4.0/bin/rake assets:precompile RAILS_ENV=production
380
+
381
+ #
382
+
383
+ # 10月 11 07:01:56 ip-10-0-1-127.ap-northeast-1.compute.internal systemd[1]: start-app.service holdoff time over, scheduling restart.
384
+
385
+ # 10月 11 07:01:56 ip-10-0-1-127.ap-northeast-1.compute.internal systemd[1]: Started start-app daemon.
386
+
387
+ # 10月 11 07:01:56 ip-10-0-1-127.ap-northeast-1.compute.internal systemd[1]: Starting start-app daemon...
388
+
389
+ ```

1

教えていただいた内容を参考に修正し、エラーを追記しました

2019/10/11 07:21

投稿

begenner
begenner

スコア79

test CHANGED
File without changes
test CHANGED
@@ -189,3 +189,109 @@
189
189
  [root@ip-xxx init.d]$ chkconfig application-starter on
190
190
 
191
191
  ```
192
+
193
+
194
+
195
+ ### 追記(10/11)
196
+
197
+ [yu_1985](https://teratail.com/users/yu_1985#reply)さんに教えていただいた[URL](https://qiita.com/DQNEO/items/0b5d0bc5d3cf407cb7ff)を参考にして、
198
+
199
+ - 自動起動スクリプトの作成を削除
200
+
201
+ - Unit定義ファイルを作成
202
+
203
+ - `sudo systemctl list-unit-files --type=service | grep start`を実行
204
+
205
+
206
+
207
+ しましたが、ステータス確認でstatusが`failed`の状態でうまくいきませんでした。
208
+
209
+ ```bash
210
+
211
+ $ sudo systemctl status start-app
212
+
213
+ # ● start-app.service - start-app daemon
214
+
215
+ # Loaded: loaded (/etc/systemd/system/start-app.service; enabled; vendor preset: disabled)
216
+
217
+ # Active: failed (Result: start-limit) since 金 2019-10-11 00:10:52 UTC; 14min ago
218
+
219
+ # Main PID: 5821 (code=exited, status=127)
220
+
221
+ #
222
+
223
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service: main process exited, code=exited, status=127/n/a
224
+
225
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Unit start-app.service entered failed state.
226
+
227
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service failed.
228
+
229
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service holdoff time over, scheduling restart.
230
+
231
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start request repeated too quickly for start-app.service
232
+
233
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Failed to start start daemon.
234
+
235
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Unit start-app.service entered failed state.
236
+
237
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service failed.
238
+
239
+ ```
240
+
241
+
242
+
243
+ 02-01. Unit定義ファイルを作成する
244
+
245
+ ```bash
246
+
247
+ # etc/systemd/system/start-app.service
248
+
249
+ [Unit]
250
+
251
+ Description = start-app daemon
252
+
253
+
254
+
255
+ [Service]
256
+
257
+ ExecStart = /home/myusername/start.sh
258
+
259
+ Restart = always
260
+
261
+ Type = simple
262
+
263
+
264
+
265
+ [Install]
266
+
267
+ WantedBy = multi-user.target
268
+
269
+ ```
270
+
271
+ 02-02. UnitがServiceとして認識されたか確認する
272
+
273
+ ```bash
274
+
275
+ $ sudo systemctl list-unit-files --type=service | grep start
276
+
277
+ # plymouth-start.service disabled
278
+
279
+ # start-app.service enabled
280
+
281
+ ```
282
+
283
+
284
+
285
+ 02-03. 自動起動の設定、起動
286
+
287
+ ```bash
288
+
289
+ # 自動起動on
290
+
291
+ $ sudo systemctl enable start-app
292
+
293
+ # 起動
294
+
295
+ $ sudo systemctl start start-app
296
+
297
+ ```