LoginSignup
2
3

More than 5 years have passed since last update.

Raspberry Pi 3 でサービス作って自動起動(systemd)

Last updated at Posted at 2017-11-15

ラズパイのプロジェクト配下にサービスを設置してシンボリックリンクを張って、systemdで自動起動設定をする

株式会社XSHELL デベロッパー 植田歩

環境

  • mac OS X El Capitan
  • Raspberry Pi 3
  • OS 2017-08-16-raspbian-stretch-lite.img

手順

/etc/systemd/systemから~/git/office_monitorにシンボリックリンクをはり、自動起動設定をする
シンボリックリンク作成


sudo ln -s ~/git/office-monitor/office-monitor.service /etc/systemd/system
sudo service office-monitor start
sudo service office-monitor stop

.serviceの書き方は調べてください。
一応サンプルです。
別プロジェクトのものなのでパスとサービス名が違います。


[Unit]
Description=thermo
Before=network.target
After=syslog.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/thermo
ExecStart=/usr/bin/python2 /home/pi/thermo/serial-thermo.py
ExecStop=
Restart = always
TimeoutStopSec=60
StandardOutput=null

[Install]
WantedBy = multi-user.target

下記、自動起動設定コマンド

sudo systemctl enable office-monitor.service
sudo systemctl status office-monitor.service

XSHELLはSBCを使いやすくするソリューションを提供しています。
isaaxIoTitぜひご使用になってご意見を頂きたく思います。
共に素晴らしいプロジェクトを実現させましょう!


2
3
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
2
3