Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- frederick@Frederick-PC:~$ sudo systemctl start my_program.service
- frederick@Frederick-PC:~$ journalctl _SYSTEMD_UNIT=my_program.service
- No journal files were found.
- -- No entries --
- [Unit]
- Description=Start my_program client after system is booted
- [Service]
- Type=forking
- ExecStart=/usr/bin/my_program.sh start
- ExecStop=/usr/bin/my_program.sh stop
- PIDFile=/run/my_program.pid
- WorkingDirectory=/home/frederick/Applications/my_program-go/
- StandardOutput=journal+console
- [Install]
- WantedBy=multi-user.target
- #!/bin/sh
- start() {
- if [ -f /run/my_program.pid ]; then
- kill -0 $(cat /run/my_program.pid) > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- echo "my_program has been already started"
- exit 1
- fi
- fi
- echo -n "Starting my_program... "
- nohup /home/frederick/Applications/my_program-go/my_program-local -c /home/frederick/Applications/my_program-go/config.json >> /home/frederick/Applications/my_program-go/my_program.log 2>&1 &
- if [ $? -gt 0 ]; then
- echo "failed"
- rm /run/my_program.pid > /dev/null 2>&1
- else
- echo $! | tee /run/my_program.pid
- fi
- }
- stop() {
- if [ -f /run/my_program.pid ]; then
- echo -n "Stopping my_program... "
- msg=$(kill $(cat /run/my_program.pid) 2>&1)
- if [ $? -gt 0 ]; then
- echo "failed"
- echo $msg
- else
- rm /run/my_program.pid > /dev/null 2>&1
- echo "succeeded"
- fi
- else
- echo "my_program not started"
- fi
- }
- restart() {
- stop
- start
- }
- case $1 in
- start|stop|restart)
- "$1"
- ;;
- *)
- echo "No such operation"
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement