Open3
systemdメモ

systemdで適当にサービスをつくる
unitファイル作成はsystemctl edit
でやると便利。
- ユニットファイルのディレクトリを覚えなくてよい
- 編集後の再読み込み等、必要な処理を勝手にやってくれる
新規作成:
sudo systemctl edit --force --full hoge.service
これを実行するとエディタが開き編集した内容が/etc/systemd/system/hoge.service
に保存される。
直接編集:
ドロップイン等を活用せず直接編集する場合。自作serviceの場合はほとんどの場合当てはまると思われる。
sudo systemctl edit --full hoge.service

マイクラサーバーpaperを動かすユニットファイルの例
[Unit]
Description=paper minecraft server
#After=network-online.target
#Wants=network-online.target
[Service]
User=minecraft
WorkingDirectory=/opt/minecraft/data
ExecStart=java -Xmx8192M -Xms8192M -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MaxNewSizePercent=40 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1NewSizePercent=30 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar server.jar nogui
SuccessExitStatus=143
Restart=always
TimeoutStartSec=240
[Install]
WantedBy=multi-user.target

メモ:ubuntuでデフォルトのエディタをvimにする
sudo update-alternatives --config editor