Ubuntu: Start/Stop a program with ‘service’ command

s
# Step
1. Define a servicename
2. Create a script in /etc/init.d/[SERVICE_NAME]

#!/bin/bash
PIDFILE=/var/run/tomcat
DAEMON_START=/vol/users/gatekeeper.tvsw/program/apache-tomcat-7.0.55/bin/startup.sh
DAEMON_SHUTDOWN=/vol/users/gatekeeper.tvsw/program/apache-tomcat-7.0.55/bin/shutdown.sh
DAEMON_ARGS=""
case "$1" in
    start)
        start-stop-daemon --start --quiet  --chuid gatekeeper.tvsw:users --pidfile $PIDFILE --exec $DAEMON_START -- \
            $DAEMON_ARGS || return 2
        ;;
    stop)
#        start-stop-daemon --stop --quiet --oknodo  --retry=0/30/KILL/5  --pidfile $PIDFILE --name jenkins_hq
        start-stop-daemon --start --quiet  --chuid gatekeeper.tvsw:users --pidfile $PIDFILE --exec $DAEMON_SHUTDOWN -- \
            $DAEMON_ARGS || return 2
        #/home/jenkins_hq/program/apache-tomcat-7.0.57/bin/shutdown.sh
        ;;
    *)
        echo "Usage : $0 {start|stop}"
        exit 1
        ;;
esac

“$1” means a first parameter of a script. For example, if you use this command to start a service,

service tomcat start

“$1” is ‘start’

3. Use ‘update-rc.d’ in ordert to register a script you created

sudo update-rc.d tomcat defaults

#Watch out!
1. When you start/stop a service, please use ‘start-stop-daemon’ command with an option ‘–chuid’.
If you do not use that option, a service you registred is runned with root account

Advertisements

Get a custom field object and update its value to be displayed

In order to update a custom field’s value, please follow these stesp

  1. Get an mutable issue object
  2. Get ‘ComponentManager’¬†object
  3. Get ‘CustomFieldManager’ object
  4. Get an custom field object with an custom field id (like 10106)
  5. Update custome field’s value
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField

//Get an mutable issue object
MutableIssue myIssue = issue

issueKey =  myIssue.getKey()

//Get 'ComponentManager' Object
componentManager = ComponentManager.getInstance()
//Get 'CustomFieldManager' Object
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

//Get Custom Field Object
CustomField codeReview = customFieldManager.getCustomFieldObject(10106)

//Update Custom field's value.
myIssue.setCustomFieldValue(codeReview, issueKey)

passesCondition = false

You can select custom field object with its name. But it’s better to use field id numeric value because it’s not changed after a custom field was created. With this feature, you can change field name .

Get JIRA issue key when using ‘Script Runner’ groovy script in a JIRA workflow transition

If you need to get a current issue’s key value and you use ‘groovy’, you can use this code

import com.atlassian.jira.issue.Issue

Issue issue  = issue

issueKey =  issue.getKey()