Custom systemd service in Linux

  1. 1. custom systemd service

custom systemd service

  • service file in /lib/systemd/system
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=ss local server
After=network.target network-online.target systemd-networkd.service NetworkManager.service connman.service
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/usr/bin/ss-local
ExecStop=/bin/kill -s QUIT $MAINPID
[Install]
WantedBy=multi-user.target
  • operations
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # make change take effect
    sudo systemctl daemon-reload
    # start service
    sudo service ss-local start
    # stop service
    sudo service ss-local stop
    # view log
    journalctl -xe