Start service on system startup using Upstart

I’m using Upstart Event System to start uTorrent server when system is up. The setup process is pretty simple and the most useful advantage is- if the job gets terminated then it would be restarted.

Setting up job configuration file-

#/etc/init/utserver.conf

description "Start utorrent server on system startup"
author "Kuntal Chandra"

respawn 
respawn limit 5 10

env LOG_FILE=/var/log/custom.log

pre-start script
    echo "utserver started at" $(date +'%Y-%m-%d %R') >> $LOG_FILE
end script

start on runlevel [2345]
stop on shutdown

exec utserver -settingspath /opt/utorrent-server-alpha-v3_3/

post-stop script
    echo "utserver stopped at" $(date +'%Y-%m-%d %R') >> $LOG_FILE
end script

Update chmod
sudo chmod 755 /etc/init/utserver.conf

Check the configuration file syntax

$ init-checkconf /etc/init/utserver.conf
File /etc/init/utserver.conf: syntax ok

The basic command syntax is

sudo service utserver status

On next restart the output should be

$ sudo service utserver status
utserver start/running, process 1436

These are basic possible controls-

restart: this will stop, then start a service
start: this will start a service, if it’s not running
stop: this will stop a service, if it’s running
status: this will display the status of a service

That’s all to start and stop utorrent server on system start up and shut down.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s