とりあえず日記

VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ(いまここ🍄)

Free Client for OneDrive on Linuxをサービス化する

はじめに

Free Client for OneDrive on LinuxをCentOS7でサービス化する方法です。
GitHub - skilion/onedrive: Free Client for OneDrive on Linux

OneDriveをインストールする

yum install onedrive - とりあえず日記

コマンドを作る

/opt/onedrive.sh というスクリプトを用意します。

onedriveをhogeという一般ユーザーで実行しています。

/opt/onedrive.sh

#!/bin/bash
sudo -u hoge onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive

実行権限を与えます。

sudo chmod 0755 /opt/onedrive.sh

/etc/systemd/system/ の下にUnit定義ファイルを作る

/etc/systemd/system/onedrive.service

[Unit]
Description = onedrive daemon

[Service]
ExecStart = /opt/onedrive.sh
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target

UnitがServiceとして認識されたか確認する

$ sudo systemctl list-unit-files --type=service | grep onedrive
onedrive.service disabled

systemctlコマンドでUnitを起動する

# 自動起動on
$ sudo systemctl enable onedrive
# 起動
$ sudo systemctl start onedrive

状態の確認。

$ systemctl status onedrive

● onedrive.service - onedrive daemon
Loaded: loaded (/etc/systemd/system/onedrive.service; enabled; vendor preset: disabled)
Active: active (running) since 土 2018-02-10 14:28:04 JST; 4s ago
Main PID: 1287 (onedrive.sh)
CGroup: /system.slice/onedrive.service
├─1287 /bin/bash /opt/onedrive.sh
├─1288 sudo -u hoge onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive
└─1289 onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive

2月 10 14:28:04 localhost.localdomain systemd[1]: Started onedrive daemon.
2月 10 14:28:04 localhost.localdomain systemd[1]: Starting onedrive daemon...
2月 10 14:28:05 localhost.localdomain sudo[1288]: root : TTY=unknown ; PWD=/ ; USER=hoge ; COMMAND=/bin/onedr...drive
Hint: Some lines were ellipsized, use -l to show in full.