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

Configure

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

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

Control

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 somehost:X.new
ssh gregory@somehost 'systemctl stop X; mv X.new bin/X; systemctl start X