scripts

This folder contains shell scripts which will be executed during the installation, un-installation, upgrading, starting, and stopping of packages. Package Center will put the scripts to /var/packages/[package identify]/scripts/ after the package is installed. There are seven basic script files stored in the scripts folder.

  1. preinst: This script is run before the package files are transferred to @appstore. You can check if the installation requirements meet the DSM or package version, or if some services are enabled in this script.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  2. postinst: This script is run after the package files are transferred to @appstore. You can change the file permission and ownership in this script.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  3. preuninst: This script is run before the package is removed.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  4. postuninst: This script is run after the package is removed from the system.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  5. preupgrade: Package Center will call this script before uninstalling the old version of your package.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user(e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  6. postupgrade: Package Center will call this script after installing the new version of your package.
    For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user(e.g. echo "Hello!!" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.

  7. start-stop-status: This script is used to start and stop a package, detect running status, and generate the log file. Parameters used by the script are listed in below:

    1. start: When the user clicks "Run" to run the package or the NAS is turned on, the Package Center will call this script with the "start" parameter. A returned value will then be acquired.
      For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Start failed" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.
    2. stop: When the user clicks "Stop" to stop running the package or the NAS is turned off, the Package Center will call this script with the "stop" parameter. A returned value will then be acquired.
      For non-zero returned values, you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Stop failed" > $SYNOPKG_TEMP_LOGFILE). You can also write messages in the SYNOPKG_TEMP_LOGFILE file for zero returned values which represent that the process was successful.
    3. status: When Package Center is opened to check package status, it will send a request to ask the status of the package using this parameter. The following exit status codes should be returned:
      0: package is running.
      1: program of package is dead and /var/run pid file exists.
      2: program of package is dead and /var/lock lock file exists
      3: package is not running
      4: package status is unknown
      150: package is broken and should be reinstalled. Please note, broken status (150) is only supported by DSM 4.2 and later.
      
    4. log: When a log page is opened in Package Center, Package Center will send a request to ask the log of the package using this parameter. When the log file name is sent to STDOUT, the content of the log file will be displayed.
    5. prestart: If precheckstartstop in INFO is set to "yes", it is run for checking if it's allowed to the end user to start your package in some situations or not. For zero returned value, the end user can start your package. For non-zero returned values, the end user isn't allowed to start your package and you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Start failed" > $SYNOPKG_TEMP_LOGFILE)

      Note:

      1. It only works in DSM 6.0 or newer.
      2. It won't run after starting a package at booting up.
    6. prestop: If precheckstartstop in INFO is set to "yes", it is run for checking if it's allowed to the end user to stop your package in some situations or not. For zero returned value, the end user can stop your package. For non-zero returned values, the end user isn't allowed to stop your package and you can compile error messages in the SYNOPKG_TEMP_LOGFILE file to prompt the user (e.g. echo "Stop failed" > $SYNOPKG_TEMP_LOGFILE)

      Note:

      1. It only works in DSM 6.0 or newer.
      2. It won't run before stopping a package at shutting down.

To install a package:

  • preinst
  • postinst
  • start-stop-status with prestart argument if end user chooses to start it immediately
  • start-stop-status with start argument if end user chooses to start it immediately

To upgrade a package:

  • start-stop-status with prestop argument if it has been started
  • start-stop-status with stop argument if it has been started
  • preupgrade
  • preuninst
  • postuninst
  • preinst
  • postinst
  • postupgrade
  • start-stop-status with prestart argument if it was started before being upgraded
  • start-stop-status with start argument if it was started before being upgraded

To uninstall a package:

  • start-stop-status with prestop argument if it has been started
  • start-stop-status with stop argument if it has been started
  • preuninst
  • postuninst

To start a package:

  • start-stop-status with prestart argument
  • start-stop-status with start argument

To stop a package:

  • start-stop-status with prestop argument
  • start-stop-status with stop argument

Note: start-stop-status with prestart or prestop argument is only supported in DSM 6.0 or newer.