Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ branch:  cross package maker


Check-in [2f31b121c8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1:2f31b121c8c0633daf8532f2b3eb18c72f404a70
Date: 2014-10-25 05:27:26
User: jls
Comment:Merge pull request #776 from Tapjoy/feature/sh_template_enhancements Enhancements to sh template
Tags And Properties
  • sym-trunk inherited from [2b439be7d6]
Context
2014-10-25
05:28
[d84b9cf55e] Move from @logger ivar to logger method. Tests pass. Hope is all we have. And hugs. (user: jls, tags: trunk)
05:27
[2f31b121c8] Merge pull request #776 from Tapjoy/feature/sh_template_enhancements Enhancements to sh template (user: jls, tags: trunk)
05:19
[a8cfee59be] Merge pull request #760 from malinoff/patch-1 Missing space in help (user: jls, tags: trunk)
2014-10-03
18:39
[00f11d900e] Enhancements to sh template This PR includes two significant changes: * If this version of the code is already in current: * If not forced, do not install the code * If forced, rename the old directory and write out a new one * Ignore functions in environment when saving .install-metadata, due to an issue with FPM 1.25.29-31 and Bash 4.3.27 (user: chris.gerber, tags: trunk)
Changes

Changes to templates/sh.erb.

17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48




























49
50
51
52
53
54
55
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#                is used. Then it is $INSTALL_ROOT/releases/<datestamp>
# CURRENT_DIR  = if -c argument is used, this is set to the $INSTALL_ROOT/current which is
#                symlinked to INSTALL_DIR
# VERBOSE      = is set if the package was called with -v for verbose output
function main() {
    set_install_dir

    create_pid


    wait_for_others

    kill_others

    set_owner

    unpack_payload

    if [ "$UNPACK_ONLY" == "1" ] ; then
        echo "Unpacking complete, not moving symlinks or restarting because unpack only was specified."
    else
        create_symlinks

        set +e # don't exit on errors to allow us to clean up
        if ! run_post_install ; then
            revert_symlinks
            log "Installation failed."
            exit 1
        else
            clean_out_old_releases
            log "Installation complete."
        fi
    fi




























}

# deletes the PID file for this installation
function delete_pid(){
    rm -f ${INSTALL_ROOT}/$$.pid 2> /dev/null
}

................................................................................

# write out metadata for future installs
function save_environment(){
    local METADATA=$1
    echo -n "" > ${METADATA} # empty file

    # just piping env to a file doesn't quote the variables. This does
    # filter out multiline junk and _. _ is a readonly variable
    env | egrep "^[^ ]+=.*" | grep -v "^_=" | while read ENVVAR ; do
        local NAME=${ENVVAR%%=*}
        # sed is to preserve variable values with dollars (for escaped variables or $() style command replacement),
        # and command replacement backticks
        # Escaped parens captures backward reference \1 which gets replaced with backslash and \1 to esape them in the saved
        # variable value
        local VALUE=$(eval echo '$'$NAME | sed 's/\([$`]\)/\\\1/g')
        echo "export $NAME=\"$VALUE\"" >> ${METADATA}







|

>
|
<
|
<
|
<
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|







17
18
19
20
21
22
23
24
25
26
27

28

29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#                is used. Then it is $INSTALL_ROOT/releases/<datestamp>
# CURRENT_DIR  = if -c argument is used, this is set to the $INSTALL_ROOT/current which is
#                symlinked to INSTALL_DIR
# VERBOSE      = is set if the package was called with -v for verbose output
function main() {
    set_install_dir

    if ! slug_already_current ; then

      create_pid
      wait_for_others

      kill_others

      set_owner

      unpack_payload

      if [ "$UNPACK_ONLY" == "1" ] ; then
          echo "Unpacking complete, not moving symlinks or restarting because unpack only was specified."
      else
          create_symlinks

          set +e # don't exit on errors to allow us to clean up
          if ! run_post_install ; then
              revert_symlinks
              log "Installation failed."
              exit 1
          else
              clean_out_old_releases
              log "Installation complete."
          fi
      fi

    else
        echo "This slug is already installed in 'current'. Specify -f to force reinstall. Exiting."
    fi
}

# check if this slug is already running and exit unless `force` specified
# Note: this only works with RELEASE_ID is used
function slug_already_current(){
    local this_slug=$(basename $0 .slug)
    local current=$(basename "$(readlink ${INSTALL_ROOT}/current)")
    log "'current' symlink points to slug: ${current}"

    if [ "$this_slug" == "$current" ] ; then
        if [ "$FORCE" == "1" ] ; then
        log "Force was specified. Proceeding with install after renaming live directory to allow running service to shutdown correctly."
            local real_dir=$(readlink ${INSTALL_ROOT}/current)
            if [ -f ${real_dir}.old ] ; then
                # remove that .old directory, if needed
                rm -rf ${real_dir}.old
            fi
            mv ${real_dir} ${real_dir}.old
            mkdir -p ${real_dir}
        else
            return 0;
        fi
    fi
    return 1;
}

# deletes the PID file for this installation
function delete_pid(){
    rm -f ${INSTALL_ROOT}/$$.pid 2> /dev/null
}

................................................................................

# write out metadata for future installs
function save_environment(){
    local METADATA=$1
    echo -n "" > ${METADATA} # empty file

    # just piping env to a file doesn't quote the variables. This does
    # filter out multiline junk, _, and functions. _ is a readonly variable.
    env | grep -v "^_=" | grep -v "^[^=(]*()=" | egrep "^[^ ]+=" | while read ENVVAR ; do
        local NAME=${ENVVAR%%=*}
        # sed is to preserve variable values with dollars (for escaped variables or $() style command replacement),
        # and command replacement backticks
        # Escaped parens captures backward reference \1 which gets replaced with backslash and \1 to esape them in the saved
        # variable value
        local VALUE=$(eval echo '$'$NAME | sed 's/\([$`]\)/\\\1/g')
        echo "export $NAME=\"$VALUE\"" >> ${METADATA}