質問するログイン新規登録

質問編集履歴

2

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

2019/10/11 07:21

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -146,4 +146,50 @@
146
146
  $ sudo systemctl enable start-app
147
147
  # 起動
148
148
  $ sudo systemctl start start-app
149
+ ```
150
+
151
+
152
+ ### 追記3
153
+ ごにょごにょしてたらstatusに表示されるメッセージが変更されていたので追記します。
154
+ 依然としてどの処理でエラーが発生しているのか、動作の妨げになっているのかわかりません(m_ _m)
155
+ 参考: [[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/)
156
+
157
+ ```bash
158
+ [Unit]
159
+ Description = start-app daemon
160
+
161
+ [Service]
162
+ User = myusername
163
+
164
+ # 環境変数パス
165
+ EnvironmentFile=/etc/systemd/env
166
+
167
+
168
+ ExecStart = /home/myusername/start.sh
169
+ Restart = always
170
+ Type = simple
171
+
172
+ [Install]
173
+ WantedBy = multi-user.target
174
+ ```
175
+
176
+ ```bash
177
+ # /etc/systemd/env
178
+ 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
179
+ ```
180
+
181
+ #### 追記、修正後の結果
182
+ ```bash
183
+ [myusername@ip-10-0-1-127 ~]$ sudo systemctl status start-app.service
184
+ # ● start-app.service - start-app daemon
185
+ # Loaded: loaded (/etc/systemd/system/start-app.service; enabled; vendor preset: disabled)
186
+ # Active: active (running) since 金 2019-10-11 07:01:56 UTC; 4s ago
187
+ # Main PID: 3842 (start.sh)
188
+ # CGroup: /system.slice/start-app.service
189
+ # ├─3842 /bin/sh /home/myusername/start.sh
190
+ # └─3843 /var/www/rails/myapp/vendor/bundle/ruby/2.4.0/bin/rake assets:precompile RAILS_ENV=production
191
+ #
192
+ # 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.
193
+ # 10月 11 07:01:56 ip-10-0-1-127.ap-northeast-1.compute.internal systemd[1]: Started start-app daemon.
194
+ # 10月 11 07:01:56 ip-10-0-1-127.ap-northeast-1.compute.internal systemd[1]: Starting start-app daemon...
149
195
  ```

1

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

2019/10/11 07:21

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -93,4 +93,57 @@
93
93
  [root@ip-xxx init.d]$ chmod +r application-starter
94
94
  [root@ip-xxx init.d]$ chkconfig --add application-starter
95
95
  [root@ip-xxx init.d]$ chkconfig application-starter on
96
+ ```
97
+
98
+ ### 追記(10/11)
99
+ [yu_1985](https://teratail.com/users/yu_1985#reply)さんに教えていただいた[URL](https://qiita.com/DQNEO/items/0b5d0bc5d3cf407cb7ff)を参考にして、
100
+ - 自動起動スクリプトの作成を削除
101
+ - Unit定義ファイルを作成
102
+ - `sudo systemctl list-unit-files --type=service | grep start`を実行
103
+
104
+ しましたが、ステータス確認でstatusが`failed`の状態でうまくいきませんでした。
105
+ ```bash
106
+ $ sudo systemctl status start-app
107
+ # ● start-app.service - start-app daemon
108
+ # Loaded: loaded (/etc/systemd/system/start-app.service; enabled; vendor preset: disabled)
109
+ # Active: failed (Result: start-limit) since 金 2019-10-11 00:10:52 UTC; 14min ago
110
+ # Main PID: 5821 (code=exited, status=127)
111
+ #
112
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service: main process exited, code=exited, status=127/n/a
113
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Unit start-app.service entered failed state.
114
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service failed.
115
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service holdoff time over, scheduling restart.
116
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start request repeated too quickly for start-app.service
117
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Failed to start start daemon.
118
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: Unit start-app.service entered failed state.
119
+ # ip-xxx.ap-northeast-1.compute.internal systemd[1]: start-app.service failed.
120
+ ```
121
+
122
+ 02-01. Unit定義ファイルを作成する
123
+ ```bash
124
+ # etc/systemd/system/start-app.service
125
+ [Unit]
126
+ Description = start-app daemon
127
+
128
+ [Service]
129
+ ExecStart = /home/myusername/start.sh
130
+ Restart = always
131
+ Type = simple
132
+
133
+ [Install]
134
+ WantedBy = multi-user.target
135
+ ```
136
+ 02-02. UnitがServiceとして認識されたか確認する
137
+ ```bash
138
+ $ sudo systemctl list-unit-files --type=service | grep start
139
+ # plymouth-start.service disabled
140
+ # start-app.service enabled
141
+ ```
142
+
143
+ 02-03. 自動起動の設定、起動
144
+ ```bash
145
+ # 自動起動on
146
+ $ sudo systemctl enable start-app
147
+ # 起動
148
+ $ sudo systemctl start start-app
96
149
  ```