Armadilloフォーラム

rubyスクリプトの自動起動

amami

2018年7月28日 17時36分

こんちには。

rubyのスクリプトを起動時に自動起動させたいのですが、うまくできません。
方法をご教授いただけませんでしょうか。

○環境
atmark@armadillo:~$ uname -a
Linux armadillo 3.14.79-at21 #2 SMP PREEMPT Tue Feb 27 09:49:09 JST 2018 armv7l GNU/Linux

○やったこと
・chmod 777 test.rbとして、rubyのスクリプトに実行権限を与えた
・/etc/rc.localに「ruby /home/atmark/test.rb &」と記述

○事象
・ps auxとしてもスクリプトが起動しておらず、またスクリプトを起動すると生成されるはずのファイルも生成されていなかった

以上、よろしくお願いします。

コメント

y.nakamura

2018年7月28日 18時06分

中村です。

> ・chmod 777 test.rbとして、rubyのスクリプトに実行権限を与えた
> ・/etc/rc.localに「ruby /home/atmark/test.rb &」と記述
...
> ・ps auxとしてもスクリプトが起動しておらず、またスクリプトを起動すると生成されるはずのファイルも生成されていなかった

rootでログインして
systemctl -l status rc-local.service
をやるとどうなりますか?

ログインするシリアルコンソールの横幅を倍くらいに
広げておいた方がいいかもしれません。

--
なかむら

y.nakamura

2018年7月28日 18時13分

中村です。

常駐するプログラム(「サービス」ということも)ならば、
rc.localからバクグラウンドで起動するよりも、
systemdのサービスの設定ファイルを作って動かす方が
いいと思います。

参考:
[Armadillo-X1, Armadillo-IoT G3/G3L: systemdでアプリを自動起動する方法(その1) ]
https://users.atmark-techno.com/blog/6938/2865

[rmadillo-X1, Armadillo-IoT G3/G3L: systemdでアプリを自動起動する方法(その2)〜起動順序を設定する〜 ]
https://users.atmark-techno.com/blog/6938/2898

めんどくさそうに見えますが、設定ファイルの書き方などが
わかってしまえば簡単に設定できます。

--
なかむら

amami

2018年7月28日 18時59分

中村さま、

ご連絡ありがとうございます。

○systemctl -l status rc-local.serviceについて
root@armadillo:~# systemctl -l status rc-local.service
● rc-local.service - /etc/rc.local
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled)
Active: failed (Result: start-limit) since Thu 1970-01-01 09:01:09 JST; 48 years 6 months ago
Process: 2621 ExecStart=/etc/rc.local (code=exited, status=0/SUCCESS)
Main PID: 2621 (code=exited, status=0/SUCCESS)

Jan 01 09:01:09 armadillo systemd[1]: rc-local.service holdoff time over, scheduling restart.
Jan 01 09:01:09 armadillo systemd[1]: Stopping /etc/rc.local...
Jan 01 09:01:09 armadillo systemd[1]: Starting /etc/rc.local...
Jan 01 09:01:09 armadillo systemd[1]: rc-local.service start request repeated too quickly, refusing to start.
Jan 01 09:01:09 armadillo systemd[1]: Failed to start /etc/rc.local.
Jan 01 09:01:09 armadillo systemd[1]: Unit rc-local.service entered failed state.

○systemdについて
以下のように作成してみましたが、自動起動しませんでした。
[Unit]
Description = system_init_test daemon

[Service]
ExecStart = /home/atmark/test.rb
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target

journalctlコマンドを実行すると、以下のようになります。
root@armadillo:~# journalctl -o short-precise | grep _test
Jan 01 09:01:01.061437 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:01.100003 armadillo systemd[1]: Started system_init_test daemon.
Jan 01 09:01:02.115274 armadillo systemd[1]: system_init_test.service: main process exited, code=exited, status=203/EXEC
Jan 01 09:01:02.118528 armadillo systemd[1]: Unit system_init_test.service entered failed state.
Jan 01 09:01:02.483816 armadillo systemd[1]: system_init_test.service holdoff time over, scheduling restart.
Jan 01 09:01:04.361614 armadillo systemd[1]: Stopping system_init_test daemon...
Jan 01 09:01:04.406397 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:04.438285 armadillo systemd[1]: Started system_init_test daemon.
Jan 01 09:01:04.736067 armadillo systemd[1]: system_init_test.service: main process exited, code=exited, status=203/EXEC
Jan 01 09:01:04.760739 armadillo systemd[1]: Unit system_init_test.service entered failed state.
Jan 01 09:01:05.052049 armadillo systemd[1]: system_init_test.service holdoff time over, scheduling restart.
Jan 01 09:01:06.230525 armadillo systemd[1]: Stopping system_init_test daemon...
Jan 01 09:01:06.270463 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:06.309972 armadillo systemd[1]: Started system_init_test daemon.
Jan 01 09:01:06.331078 armadillo systemd[1]: system_init_test.service: main process exited, code=exited, status=203/EXEC
Jan 01 09:01:06.332506 armadillo systemd[1]: Unit system_init_test.service entered failed state.
Jan 01 09:01:06.435229 armadillo systemd[1]: system_init_test.service holdoff time over, scheduling restart.
Jan 01 09:01:06.481846 armadillo systemd[1]: Stopping system_init_test daemon...
Jan 01 09:01:06.520268 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:06.559955 armadillo systemd[1]: Started system_init_test daemon.
Jan 01 09:01:06.561517 armadillo systemd[1]: system_init_test.service: main process exited, code=exited, status=203/EXEC
Jan 01 09:01:06.572957 armadillo systemd[1]: Unit system_init_test.service entered failed state.
Jan 01 09:01:06.679292 armadillo systemd[1]: system_init_test.service holdoff time over, scheduling restart.
Jan 01 09:01:06.696308 armadillo systemd[1]: Stopping system_init_test daemon...
Jan 01 09:01:06.696430 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:06.710712 armadillo systemd[1]: Started system_init_test daemon.
Jan 01 09:01:06.723681 armadillo systemd[1]: system_init_test.service: main process exited, code=exited, status=203/EXEC
Jan 01 09:01:06.725572 armadillo systemd[1]: Unit system_init_test.service entered failed state.
Jan 01 09:01:06.863112 armadillo systemd[1]: system_init_test.service holdoff time over, scheduling restart.
Jan 01 09:01:06.864053 armadillo systemd[1]: Stopping system_init_test daemon...
Jan 01 09:01:06.864155 armadillo systemd[1]: Starting system_init_test daemon...
Jan 01 09:01:06.864187 armadillo systemd[1]: system_init_test.service start request repeated too quickly, refusing to start.
Jan 01 09:01:06.864254 armadillo systemd[1]: Failed to start system_init_test daemon.
Jan 01 09:01:06.864363 armadillo systemd[1]: Unit system_init_test.service entered failed state.

何度もすいませんが、なにかわかりましたらよろしくお願いいたします。
> 中村です。
>
> 常駐するプログラム(「サービス」ということも)ならば、
> rc.localからバクグラウンドで起動するよりも、
> systemdのサービスの設定ファイルを作って動かす方が
> いいと思います。
>
> 参考:
> [Armadillo-X1, Armadillo-IoT G3/G3L: systemdでアプリを自動起動する方法(その1) ]
> https://users.atmark-techno.com/blog/6938/2865
>
> [rmadillo-X1, Armadillo-IoT G3/G3L: systemdでアプリを自動起動する方法(その2)〜起動順序を設定する〜 ]
> https://users.atmark-techno.com/blog/6938/2898
>
> めんどくさそうに見えますが、設定ファイルの書き方などが
> わかってしまえば簡単に設定できます。
>
> --
> なかむら
>
>

y.nakamura

2018年7月28日 19時19分

中村です。

test.rbを起動しようとしたけど起動できなかった、
あるいは、test.rbが一旦は起動したけど何もできずにすぐに落ちた、
というようなことのようですね。

test.rbを動かすための条件というか、何かが足りないのだと思います。
実行パスとかライブラリのパスとか・・・・かな。

--
なかむら