Control service with systemd

Setup a new service with systemd. In this example the service name is X and It will be run as the user gregory


Create file X.service
[Unit] Description=X service After=auditd.service systemd-user-sessions.service [Service] User=gregory TimeoutStartSec=0 Type=simple KillMode=process WorkingDirectory=/tmp/ ExecStart=/home/gregory/bin/X Restart=always RestartSec=2 LimitNOFILE=5555 [Install]


cp X.service /lib/systemd/system/
chmod 0664 /lib/systemd/system/X.service
systemctl daemon-reload
systemctl enable X.service
systemctl start X
systemctl status X


Allow yourself to control service
sudo usermod -a -G sudo gregory
Upload and reload service, note the .new suffix as a running service cannot be overwritten
scp X
ssh gregory@somehost 'systemctl stop X; mv bin/X; systemctl start X