Skip to content

Commit 329b81b

Browse files
committed
add db creation to demoservice
- add demo of creating an mysql db with resource definition - add uninstall wizard to optionally drop the database and/or the db user
1 parent 72b16fc commit 329b81b

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

spk/demoservice/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ SPK_VERS = 1.2
33
SPK_REV = 6
44
SPK_ICON = src/demoservice.png
55

6+
# force noarch target
67
override ARCH=
78

89
MAINTAINER = ymartin59
9-
DESCRIPTION = Demonstration package to show installer script capabilities when requiring non-root user for background service
10+
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.
1011
RELOAD_UI = yes
1112
DISPLAY_NAME = DemoService
12-
CHANGELOG = "Initial version"
13+
CHANGELOG = "Add db creation demo."
1314

1415
LICENSE = GPLv2
1516

16-
WIZARDS_DIR = src/wizard/
17+
WIZARDS_DIR = src/wizard/
18+
# The demo database is created by definitions in conf/resource and controlled by wizard variables.
19+
CONF_DIR = src/conf/
1720

1821
# 'auto' reserved value grabs SPK_NAME
1922
SERVICE_USER = auto
@@ -36,8 +39,7 @@ include ../../mk/spksrc.spk.mk
3639
.PHONY: demoservice_install
3740
# Replace standard copy/install targets, no sources, no content
3841
demoservice_install:
39-
rm -fr $(STAGING_DIR)
42+
rm -rf $(STAGING_DIR)
4043
mkdir $(STAGING_DIR)
4144
mkdir --parents $(STAGING_INSTALL_PREFIX)
42-
echo "No files package" > $(STAGING_INSTALL_PREFIX)/README
43-
45+
echo "No files package with MySQL DB creation." > $(STAGING_INSTALL_PREFIX)/README

spk/demoservice/src/conf/resource

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"mysql-db": {
3+
"info": {
4+
"db-name": "demoservice"
5+
},
6+
"root-pw": "{{wizard_mysql_password_root}}",
7+
"create-db" : {
8+
"db-collision": "skip"
9+
},
10+
"grant-user": {
11+
"user-name" : "demoservice",
12+
"rand-pw" : true
13+
},
14+
"drop-db-uninst": "{{wizard_mysql_drop_database}}",
15+
"drop-user-uninst": "{{wizard_mysql_drop_db_user}}"
16+
}
17+
}

spk/demoservice/src/demoservice.png

-6.3 KB
Loading

spk/demoservice/src/service-setup.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SERVICE_COMMAND="python -m SimpleHTTPServer ${SERVICE_PORT}"
66
SVC_CWD="${SYNOPKG_PKGDEST}"
77
SVC_BACKGROUND=y
88
SVC_WRITE_PID=y
9-
9+
DEMOSERVICE_INI=${SYNOPKG_PKGDEST}/var/demoservice.ini
1010

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

1818
service_postinst ()
1919
{
20-
echo "service_postinst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
20+
echo "service_postinst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
21+
echo "# Database created with random password:" > ${DEMOSERVICE_INI}
22+
echo "${SYNOPKG_DB_USER_RAND_PW}" >> ${DEMOSERVICE_INI}
23+
echo "ini file created: ${DEMOSERVICE_INI}" >> $INST_LOG
2124
}
2225

2326
service_preuninst ()
2427
{
2528
echo "service_preuninst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
29+
echo "wizard_mysql_drop_database = ${wizard_mysql_drop_database}" >> $INST_LOG
30+
echo "wizard_mysql_drop_db_user = ${wizard_mysql_drop_db_user}" >> $INST_LOG
2631
}
2732

28-
service_postinst ()
33+
service_postuninst ()
2934
{
3035
echo "service_postuninst ${SYNOPKG_PKG_STATUS}" >> $INST_LOG
3136
}

spk/demoservice/src/wizard/install_uifile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@
3535
]
3636
},
3737
{
38-
"step_title": "Attention! DSM Permissions",
38+
"step_title": "DSM Permissions",
3939
"items": [
4040
{
4141
"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>"
4242
}
4343
]
44+
},
45+
{
46+
"step_title": "Create MySQL Demo Database",
47+
"items": [{
48+
"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>"
49+
},{
50+
"type": "password",
51+
"desc": "Enter your MySQL root password",
52+
"subitems": [{
53+
"key": "wizard_mysql_password_root",
54+
"desc": "MySQL root password"
55+
}]
56+
}]
4457
}
45-
]
58+
]

spk/demoservice/src/wizard/install_uifile_fre

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@
3535
]
3636
},
3737
{
38-
"step_title": "Attention! DSM Permissions",
38+
"step_title": "DSM Permissions",
3939
"items": [
4040
{
4141
"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"
4242
}
4343
]
44+
},
45+
{
46+
"step_title": "Create MySQL Demo Database",
47+
"items": [{
48+
"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>"
49+
},{
50+
"type": "password",
51+
"desc": "Enter your MySQL root password",
52+
"subitems": [{
53+
"key": "wizard_mysql_password_root",
54+
"desc": "MySQL root password"
55+
}]
56+
}]
4457
}
4558
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"step_title": "MySQL Demo Database",
4+
"items": [{
5+
"type": "password",
6+
"desc": "Enter your MySQL root password if you want to drop the database and/or the db user.",
7+
"subitems": [{
8+
"key": "wizard_mysql_password_root",
9+
"desc": "MySQL root password"
10+
}]
11+
},{
12+
"type": "multiselect",
13+
"desc": "Cleanup the Demo Database:",
14+
"subitems": [{
15+
"key": "wizard_mysql_drop_database",
16+
"desc": "Drop demo database",
17+
"defaultValue": true
18+
},{
19+
"key": "wizard_mysql_drop_db_user",
20+
"desc": "Drop demo db user",
21+
"defaultValue": true
22+
}]
23+
}]
24+
}
25+
]

0 commit comments

Comments
 (0)