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 Mar 14, 2021
1 parent 72b16fc commit 329b81b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 12 deletions.
14 changes: 8 additions & 6 deletions spk/demoservice/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ SPK_VERS = 1.2
SPK_REV = 6
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.
RELOAD_UI = yes
DISPLAY_NAME = DemoService
CHANGELOG = "Initial version"
CHANGELOG = "Add db creation demo."

LICENSE = GPLv2

WIZARDS_DIR = src/wizard/
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
Expand All @@ -36,8 +39,7 @@ include ../../mk/spksrc.spk.mk
.PHONY: demoservice_install
# Replace standard copy/install targets, no sources, no content
demoservice_install:
rm -fr $(STAGING_DIR)
rm -rf $(STAGING_DIR)
mkdir $(STAGING_DIR)
mkdir --parents $(STAGING_INSTALL_PREFIX)
echo "No files package" > $(STAGING_INSTALL_PREFIX)/README

echo "No files package with MySQL DB creation." > $(STAGING_INSTALL_PREFIX)/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}}"
}
}
Binary file modified spk/demoservice/src/demoservice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions spk/demoservice/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SERVICE_COMMAND="python -m SimpleHTTPServer ${SERVICE_PORT}"
SVC_CWD="${SYNOPKG_PKGDEST}"
SVC_BACKGROUND=y
SVC_WRITE_PID=y

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

# These functions are for demonstration purpose of DSM sequence call.
# Only provide useful ones for your own package, logging may be removed.
Expand All @@ -17,15 +17,20 @@ service_preinst ()

service_postinst ()
{
echo "service_postinst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
echo "service_postinst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
echo "# Database created with random password:" > ${DEMOSERVICE_INI}
echo "${SYNOPKG_DB_USER_RAND_PW}" >> ${DEMOSERVICE_INI}
echo "ini file created: ${DEMOSERVICE_INI}" >> $INST_LOG
}

service_preuninst ()
{
echo "service_preuninst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
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_postinst ()
service_postuninst ()
{
echo "service_postuninst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
}
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 329b81b

Please sign in to comment.