Skip to content

Commit

Permalink
add db creation to demoservice
Browse files Browse the repository at this point in the history
- add demo of creating an mysql db with resource definition
- add uninstall wizard to optionally drop the database and/or the db user
  • Loading branch information
hgy59 committed Aug 5, 2022
1 parent 7083f26 commit 8f39109
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 17 deletions.
20 changes: 9 additions & 11 deletions spk/demoservice/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
SPK_NAME = demoservice
SPK_VERS = 1.2
SPK_REV = 8
SPK_REV = 9
SPK_ICON = src/demoservice.png

# force noarch target
override ARCH=

MAINTAINER = ymartin59
DESCRIPTION = Demonstration package to show installer script capabilities when requiring non-root user for background service
DESCRIPTION = Demonstration package to show installer script capabilities when requiring non-root user for background service. <br>Further more this package creates a demo MySQL database. Upon deinstallation the demo database and/or user can be kept or droped.
DISPLAY_NAME = DemoService
CHANGELOG = "1. Update with new installer logs<br/>2. Update for DSM7"
CHANGELOG = "1. Update with new installer logs<br/>2. Update for DSM7.<br/>3. Add db creation demo."

LICENSE = GPLv2

WIZARDS_DIR = src/wizard/
# The demo database is created by definitions in conf/resource and controlled by wizard variables.
CONF_DIR = src/conf/

# 'auto' reserved value grabs SPK_NAME
SERVICE_USER = auto
SERVICE_WIZARD_GROUP = wizard_group

include ../../mk/spksrc.common.mk
ifneq ($(call version_ge, ${TCVERSION}, 7.0),1)
# SERVICE_WIZARD_SHARE is not supported for DSM7 yet
SERVICE_WIZARD_SHARE = wizard_download_dir
endif

SERVICE_SETUP = src/service-setup.sh
STARTABLE = yes

Expand All @@ -41,7 +38,8 @@ include ../../mk/spksrc.spk.mk
.PHONY: demoservice_install
# Replace standard copy/install targets, no sources, no content
demoservice_pre_copy:
rm -fr $(STAGING_DIR)
rm -rf $(STAGING_DIR)
mkdir $(STAGING_DIR)
mkdir --parents $(STAGING_INSTALL_PREFIX)/var
echo "Test file for $(INSTALL_PREFIX)/var" > $(STAGING_INSTALL_PREFIX)/var/README
echo "No files package with MySQL DB creation." > $(STAGING_INSTALL_PREFIX)/var/README

17 changes: 17 additions & 0 deletions spk/demoservice/src/conf/resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mysql-db": {
"info": {
"db-name": "demoservice"
},
"root-pw": "{{wizard_mysql_password_root}}",
"create-db" : {
"db-collision": "skip"
},
"grant-user": {
"user-name" : "demoservice",
"rand-pw" : true
},
"drop-db-uninst": "{{wizard_mysql_drop_database}}",
"drop-user-uninst": "{{wizard_mysql_drop_db_user}}"
}
}
9 changes: 6 additions & 3 deletions spk/demoservice/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SERVICE_COMMAND="python -m ${SERVER_MODULE} ${SERVICE_PORT}"
SVC_CWD="${SYNOPKG_PKGVAR}"
SVC_BACKGROUND=y
SVC_WRITE_PID=y

DEMOSERVICE_INI=${SYNOPKG_PKGDEST}/var/demoservice.ini

# These functions are for demonstration purpose of DSM sequence call
# and installation logging capabilities.
Expand Down Expand Up @@ -69,13 +69,16 @@ service_preinst ()
service_postinst ()
{
echo "service_postinst ${SYNOPKG_PKG_STATUS}"

ln -sf ${INST_LOG} ${SYNOPKG_PKGVAR}/installer.log
echo "# Database created with random password:" > ${DEMOSERVICE_INI}
echo "${SYNOPKG_DB_USER_RAND_PW}" >> ${DEMOSERVICE_INI}
echo "ini file created: ${DEMOSERVICE_INI}"
}

service_preuninst ()
{
echo "service_preuninst ${SYNOPKG_PKG_STATUS}"
echo "wizard_mysql_drop_database = ${wizard_mysql_drop_database}" >> $INST_LOG
echo "wizard_mysql_drop_db_user = ${wizard_mysql_drop_db_user}" >> $INST_LOG
}

service_postuninst ()
Expand Down
17 changes: 15 additions & 2 deletions spk/demoservice/src/wizard/install_uifile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,24 @@
]
},
{
"step_title": "Attention! DSM Permissions",
"step_title": "DSM Permissions",
"items": [
{
"desc": "Permissions are managed with the group <b>'sc-download'</b> in DSM.<br>The group 'users' is no longer used as of DSM 6.<br>Package user (= demoservice) will not appear on most UI settings.<br>Including the following:<br>- Application privilege's permission viewer<br>- FPT's chroot user selector<br>- File Stations's<br>- Change owner<br>- Shared Links Manager -> Enable secure sharing<br><br>The only exceptions are:<br>- Control Panel > Shared Folder > Edit > Permission > System internal user<br>- ACL editor<br>"
}
]
},
{
"step_title": "Create MySQL Demo Database",
"items": [{
"desc": "This package creates a demo database 'demoservice' and a db user 'demoservice' with full access to this database. The password for the db user is randomly generated by DSM and is stored in the file demoservice.ini by package specific install function.<br>"
},{
"type": "password",
"desc": "Enter your MySQL root password",
"subitems": [{
"key": "wizard_mysql_password_root",
"desc": "MySQL root password"
}]
}]
}
]
]
15 changes: 14 additions & 1 deletion spk/demoservice/src/wizard/install_uifile_fre
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,24 @@
]
},
{
"step_title": "Attention! DSM Permissions",
"step_title": "DSM Permissions",
"items": [
{
"desc": "Les autorisations sont gérées avec le groupe <b>'sc-download'</b> dans DSM.<br>Le groupe 'utilisateurs' n'est plus utilisé à partir de DSM 6.<br>L'utilisateur du paquet (= demoservice) n'apparaîtra pas sur la plupart des paramètres d'interface utilisateur. Y compris ce qui suit: <br>- Afficheur d'autorisation de privilège d'application <br>- Sélecteur d'utilisateur chroot FPT <br>- File Stations's- Changer de propriétaire <br>- Shared Links Manager -> Activer le partage sécurisé <br><br>Les seules exceptions sont: <br>- Panneau de configuration> Dossier partagé> Edition> Autorisation> Utilisateur interne du système <br>- Éditeur ACL"
}
]
},
{
"step_title": "Create MySQL Demo Database",
"items": [{
"desc": "This package creates a demo database 'demoservice' and a db user 'demoservice' with full access to this database. The password for the db user is randomly generated by DSM and is stored in the file demoservice.ini by package specific install function.<br>"
},{
"type": "password",
"desc": "Enter your MySQL root password",
"subitems": [{
"key": "wizard_mysql_password_root",
"desc": "MySQL root password"
}]
}]
}
]
25 changes: 25 additions & 0 deletions spk/demoservice/src/wizard/uninstall_uifile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"step_title": "MySQL Demo Database",
"items": [{
"type": "password",
"desc": "Enter your MySQL root password if you want to drop the database and/or the db user.",
"subitems": [{
"key": "wizard_mysql_password_root",
"desc": "MySQL root password"
}]
},{
"type": "multiselect",
"desc": "Cleanup the Demo Database:",
"subitems": [{
"key": "wizard_mysql_drop_database",
"desc": "Drop demo database",
"defaultValue": true
},{
"key": "wizard_mysql_drop_db_user",
"desc": "Drop demo db user",
"defaultValue": true
}]
}]
}
]

0 comments on commit 8f39109

Please sign in to comment.