LoginSignup
66
70

More than 5 years have passed since last update.

Ubuntu16.04でスクリプトを起動時に自動実行する

Last updated at Posted at 2017-05-10

ubuntu14.04 と ubuntu16.04では、サービス管理方式が SysVinitから systemdに変更されたので、少し手順が異なります。

Ubuntu 14.04

/etc/rc.local 内に スクリプトを記述しておくと実行してくれます。

exit 0 の前に 1行追加すればよい。

Ubuntu 16.04

/etc/rc.local 内に スクリプトを記述しておくだけでは実行してくれません。

そこで、リンクの wikiを参考にしました。

1. /etc/rc.local を作ってスクリプトを記述する

2. /etc/systemd/system/rc-local.service にサービスファイルを作る

rc-local.service
[Unit]
Description=/etc/rc.local compatibility

[Service]
Type=oneshot
ExecStart=/etc/rc.local
# disable timeout logic
TimeoutSec=0
#StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

3. systemdの仕組みでサービスの自動起動設定をする

$ systemctl enable rc-local.service

追記 @170511

cronを使っても、以下のように.confに記述すれば、起動時の処理が設定できるようです。

cron.conf
@reboot <実行コマンド>

cronの使い方は前回の記事を参照してください

66
70
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
70